[英]Selenium WebDriver C#: Element.Enabled returns True even though element is disabled
I need to verify if Save button is disabled.我需要验证保存按钮是否被禁用。 I used Xpath (//a[contains(@id, 'save')])[1] to locate element.
我使用 Xpath (//a[contains(@id, 'save')])[1] 来定位元素。 But element.Enabled is returning True, even though Save button is disabled.
但是 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>
IWebElement.Enabled Property IWebElement.Enabled 属性
The Enabled property will generally return true for everything except explicitly disabled input elements.
除了显式禁用的输入元素之外, Enabled 属性通常会为所有内容返回 true。
If the element doesn't have disabled="disabled"
attribute element.Enabled
will return true
.如果元素没有
disabled="disabled"
属性element.Enabled
将返回true
。
You can parse the class
attribute to check if it has disabled
class您可以解析
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.