Reputation: 163
How does selenium webdriver decide whether a button is enabled or disabled? I have used the isEnabled() method for two buttons - one enabled and the other disabled but it returns true for both the cases. Is there a workaround other than using isEnabled() ?
Upvotes: 10
Views: 26979
Reputation: 3917
isEnabled()
is a good answer, but it has recently been updated to just Enabled
, as a getter on the IWebElement
.
Example:
Driver.findElement(By.Class("example-class-name")).Enabled
Upvotes: 2
Reputation: 462
isEnabled() checks for the disabled attribute on the button element. If the attribute "disabled" is not present, it returns True, so if you never add this attribute to disabled buttons and instead add the value "disabled" to the button's class, isEnabled() will always return true.
If you are determining whether the button is enabled or disabled based on a class, you will need to instead check for the existence of a button with the "disabled" class (find it by class name, xpath, or CSS selector) to decide what state the button is in.
Upvotes: 8