Sunday, September 06, 2009

Selenium - How to check the disabled button?

If you are using the Selenium IDE, you cannot record a test to check the disabled button. Instead of recording you can use the selenium perl driver API and code the test.
If I am testing the disabled state of a button with an id="pingBtn" in the HTML page, use the is_editable API and check the disabled state.
API doc:
Determines whether the specified input element is editable, ie hasn't been disabled.This method will fail if the specified element isn't an input element.

$locator is an element locator
Returns true if the input element is editable, false otherwise
Compare the return value to false (0) to check the disabled state and add a comment which will be printed on the test console.
ok($sel->is_editable("pingBtn") == 0, "is_not_editable, pingBtn");

No comments: