Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button enabled or disabled : How does webdriver decide?

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() ?

like image 321
Jasvinder Singh Avatar asked Dec 04 '14 11:12

Jasvinder Singh


People also ask

How does Selenium handle disabled buttons?

A button can be disabled in many ways...so you will need to think about that but a simple solution would be the assertAttribute command, using the attribute disabled . This will ensure the element has the disabled value set, which is a common way to disable elements, but not the only way.

How do I check if a button is enabled or disabled in Selenium?

How To Verify Element is Enabled or Disabled in Selenium Webdriver? To verify that the target element (Button, Check box, Dropdown, text box, Radio Button, Icons, etc ) are enabled or disabled use isEnabled() Method to check element is enabled or disabled.


1 Answers

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.

like image 157
NoSuchElephantException Avatar answered Oct 19 '22 03:10

NoSuchElephantException