Friday, April 9, 2010

How to identify Checkboxes in Watir?

Watir sets or clears checkboxes by looking at the attributes available in the HTML tag. Common attributes are id and name. For complete list see HTML Elements Supported by Watir.
What you see in the web browser:
Check Me:
This is the tag in the HTML source:
Check Me:"checkbox" id="one" name="checkme">

id Attribute

Watir code to set a checkbox using the id attribute:
ie.checkbox(:id, "one").set
Watir code to clear a checkbox using the id attribute:
ie.checkbox(:id, "one").clear

name Attribute

Watir code to set a checkbox using the name attribute:
ie.checkbox(:name, "checkme").set
Watir code to clear a checkbox using the name attribute:
ie.checkbox(:name, "checkme").clear

No comments:

Post a Comment