![](/img/trans.png)
[英]Selenium Webdriver C# element.Enabled evaluating to true when element is still disabled
[英]Selenium WebDriver C#: Element.Enabled returns True even though element is disabled
我需要驗證保存按鈕是否被禁用。 我使用 Xpath (//a[contains(@id, 'save')])[1] 來定位元素。 但是 element.Enabled 返回 True,即使保存按鈕被禁用。
<a data-info="Save" class="btn btn-primary disabled btn-xs save save_990928 lineItemControl" id="save_990928" data-request-url="/Materials/Save">
<span class="fa fa-floppy-o fa-lg lineItemControl"></span>
</a>
除了顯式禁用的輸入元素之外, Enabled 屬性通常會為所有內容返回 true。
如果元素沒有disabled="disabled"
屬性element.Enabled
將返回true
。
您可以解析class
屬性以檢查它是否已disabled
類
element.GetAttribute("class").Contains("disabled");
您可以使用 getAttribute ,獲取字符串中的屬性值,然后使用簡單的 if 條件進行比較。
String attributeValue =driver.findElement(By.xpath("xpathExpression")).getAttribute(""); if(attributeValue.contains("disabled")){ //code you want to execute }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.