Saturday, August 7, 2010

Checkboxes and Selenium

When checking (or unchecking) a checkbox, Selenium IDE might record something like this:
click - chckbx_0_0
Both the command and the location are ambiguous.

For example, let's say you're trying to
uncheck BoxA. "Click" is ambiguous because if BoxA is already unchecked, you'll check it by clicking the checkbox. "chckbx_0_0" is ambiguous as a locator because if checkboxes are added or removed from the screen in the future, "chckbx_0_0" could identify a different checkbox.

Use this instead:
command = uncheck (or check)
target (location) = relative xPath of the checkbox element

Of course, Selenium IDE recorded ambiguously on my project in this particular scenario. It will record differently depending on the application.