Friday, April 9, 2010

Watir:Text Fields: How to identify Text Fields in ruby scripting

Text Fields

Watir sets or clears a text field 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:
This is the tag in the HTML source:
"text" id="one" name="typeinme">
There is also a file upload element that looks exactly like a text_field with a "Browse" button to the right. For directions on how to interact with this control.

id Attribute

Watir code to set the text field with the string Watir World using the id attribute:
ie.text_field(:id, "one").set("Watir World")
Watir code to clear a text field using the id attribute:
ie.text_field(:id, "one").clear

name Attribute

Watir code to set the text field with the string Watir World using the name attribute:
ie.text_field(:name, "typeinme").set("Watir World")
Watir code to clear a text field using the name attribute:
ie.text_field(:name, "typeinme").clear

No comments:

Post a Comment