Buttons
In web applications, we generally submit information we have entered or selected in the web page by clicking links, buttons and images, or by hitting Enter/Return on our keyboard.
Watir clicks buttons on a web page by looking at the attributes available in the
HTML Buttons
What you see in the web browser:
This is the tag in the HTML source:
"button" id="one" name="clickme" value="Click Me">id Attribute
This is the Watir code you need to click a button using the id attribute:
ie.button(:id, "one").clickname Attribute
This is the Watir code you need to click a button using the name attribute:
ie.button(:name, "clickme").clickvalue Attribute
This is the Watir code you need to click a button using the value attribute:
ie.button(:value, "Click Me").clickImage Buttons
tag looks like an image, but acts like a button. Like HTML buttons it can be accessed by id, name and value attributes. Image buttons can also be accessed by their src attribute.
src Attribute
What you see in the web browser:
This is the tag in the HTML source:
"image" src="images/doit.gif">This is the Watir code you need to click a button with an image using the src attribute as a regular expression:
ie.button(:src, /doit/).clickIn this case we're looking for a button with doit as part of the src attribute.
Checkboxes
Watir sets or clears checkboxes by looking at the attributes available in the HTML tag. Common attributes are id and name.
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").setWatir code to clear a checkbox using the id attribute:
ie.checkbox(:id, "one").clearname Attribute
Watir code to set a checkbox using the name attribute:
ie.checkbox(:name, "checkme").setWatir code to clear a checkbox using the name attribute:
ie.checkbox(:name, "checkme").clearLinks
You can use Watir to click links in a variety of ways. Watir can click links by looking at the link text you see in the browser or by looking at the attributes available in the HTML tag. Common attributes are id, name and href. For
"http://pragmaticprogrammer.com/titles/ruby/" id="one" name="book">Pickaxe
id Attribute
Watir code to click a link using the id attribute:
ie.link(:id, "one").clickname Attribute
Watir code to click a link using the name attribute:
ie.link(:name, "book").clickText
Watir code to click a link using link's text:
ie.link(:text, "Pickaxe").clickhref Attribute
Watir code to click a link using the href attribute:
ie.link(:href, "http://pragmaticprogrammer.com/titles/ruby/").clickRadio Buttons
Watir sets or clears radio list items by looking at the attributes available in the HTML tag. Common attributes are id and name.
What you see in the web browser:
Click Me: 
This is the tag in the HTML source:
"radio" name="clickme" id="one">id Attribute
Watir code to set a radio list item using the and id attribute:
ie.radio(:id, "one").setWatir code to clear a radio list item using the id attribute:
ie.radio(:id, "one").clearname Attribute
Watir code to set a radio list item using the name attribute:
ie.radio(:name, "clickme").setWatir code to clear a radio list item using the name attribute:
ie.radio(:name, "clickme").clearSelection Boxes
Watir sets or clears an item in a selection box (or dropdown box) by looking at the attributes available in the
id Attribute
Watir code to set a select box item using the id attribute:
ie.select_list(:id, "one").set("is fun")name Attribute
Watir code to set a select box item using the name attribute:
ie.select_list(:name, "selectme").set("is fun")Selection Box Methods
Watir code to clear a select box item using the id attribute:
ie.select_list(:id, "one").clearSelectionWatir code to get the contents of a select list:
contents = ie.select_list(:id, "one").getAllContentsNOTE: contents will be an array
Select Multiple
Some select lists can have multiple selections instead of just one. If multiple items can be selected in select box, Watir can set or clear an item.
What you see in the web browser:

This is the tag in the HTML source:
You can set individual options using successive _set_s and you can clear everything that is selected with the clearSelection method. The following code would select every option in the select list and then clear everything.
ie.select_list(:id, 'one').set('Web Testing')ie.select_list(:id, 'one').set('in Ruby')ie.select_list(:id, 'one').set('is fun')ie.select_list(:id, 'one').clearSelection