Dashboard > Watir > ... > Summary > Ways Available To Identify HTML Tag
Watir Log In View a printable version of the current page.
Ways Available To Identify HTML Tag
Added by Zeljko, last edited by Zeljko on Feb 14, 2008  (view change) show comment
Labels: 

Ways Available To Identify HTML Tag

How? HTML Example Watir Example Comment
:action <form action="page.htm"> ie.form(:action, /page/).click Used only for form element, specifies the URL where the form is to be submitted.
:after? <a>one</a> <a>two</a> <a>one</a> ie.link(:after?, ie.link(:text, "two")).click Finds element after some other element.
:before? <a>one</a> <a>two</a> <a>one</a> ie.link(:before?, ie.link(:text, "two")).click Finds element before some other element.
:class <a class="header"> ie.link(:class, "header").click Used for an element that has a class attribute.
:for <label for="header"> ie.label(:for, "header").click Used only for label element.
:href <a href="page.htm"> ie.link(:href, /page/).click Used to identify a link by it's href attribute.
:id <a id="header"> ie.link(:id, "header").click Used to find an element that has an id attribute. Since each id should be unique, according to the XHTML specification, this is recommended as the most reliable method to find an object.
:index <button> ie.button(:index, 1).click Used to find the nth element of the specified type on a page. Current versions of Watir use 1-based indexing (starts counting at 1), but future versions will use 0-based indexing (starts counting at 0).
:method <form method="get"> ie.form(:method, "get").click Used only for form, the method attribute of a form is either get or post.
:name <a name="header"> ie.link(:name, "header").click Used to find an element that has a name attribute. This is useful for older versions of HTML, but name is deprecated in XHTML.
:src <img src="photo.png"> ie.image(:src, /photo/).click Used to identify an image by it's URL.
:text <a>click me</a> ie.link(:text, "click me").click Used for link, span, div and other elements that contain text.
:title <a title="header"> ie.link(:title, "header").click Used for an element that has a title attribute.
:value <input value="text"> ie.text_field(:value, "text").click Used to find a text field with a given default value, or a button with a given value.
:url <a href="page.htm"> ie.link(:url, /page/).click :url is synonym for :href.
:xpath <a href="page.htm"> ie.link(:xpath,"//a[@href='page.htm']").click Finds the item using XPath query.
multiple attribute <a>click me</a> <a>click me</a> ie.link(:text => "click me", :index => 2).click You can combine more ways of finding elements. This example will click the second link with text click me.

:id and :name are the quickest of these to process, and so should be used when possible to speed up scripts.

Go to contents, previous, next page.

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators