I need to verify if Save button is disabled. I used Xpath (//a[contains(@id, 'save')])[1] to locate element. But element.Enabled is returning True, even though Save button is disabled.
<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>
The Enabled property will generally return true for everything except explicitly disabled input elements.
If the element doesn't have disabled="disabled"
attribute element.Enabled
will return true
.
You can parse the class
attribute to check if it has disabled
class
element.GetAttribute("class").Contains("disabled");
您可以使用 getAttribute ,获取字符串中的属性值,然后使用简单的 if 条件进行比较。
String attributeValue =driver.findElement(By.xpath("xpathExpression")).getAttribute(""); if(attributeValue.contains("disabled")){ //code you want to execute }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.