Text Fields

Text Fields

Watir sets or clears a text field by looking at the attributes available in the <input type="text"> 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:

<input type="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, see File Uploads page.

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
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.