Friday, April 9, 2010

How to identify Buttons in Watir

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").click

name Attribute

This is the Watir code you need to click a button using the name attribute:
ie.button(:name, "clickme").click

value Attribute

This is the Watir code you need to click a button using the value attribute:
ie.button(:value, "Click Me").click

Image 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/).click

No comments:

Post a Comment