Friday, April 9, 2010

Ways Available To Identify HTML Element: How to identify HTML Elemnts?

How? HTML Example Watir Example Comment
ie.form(:action, /page/).click Used only for form element, specifies the URL where the form is to be submitted.
:after? one two one,, "two")).click Finds element after some other element.
:alt Continue ie.image(:alt, "Continue").click Used to find an element that has an alt attribute (img and input).
:class, "header").click Used for an element that has a class attribute.
:for ie.label(:for, "header").click Used only for label element.
:href, /page/).click Used to identify a link by it's href attribute.
:html add a term, /id=227/).click Used to identify a link by it's HTML.
: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 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 ie.form(:method, "get").click Used only for form, the method attribute of a form is either get or post.
: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 ie.image(:src, /photo/).click Used to identify an image by it's URL.
:text click me, "click me").click Used for link, span, div and other elements that contain text.
:title, "header").click Used for an element that has a title attribute.
:url, /page/).click :url is synonym for :href.
:value ie.text_field(:value, "text").click Used to find a text field with a given default value, or a button with a given value.
:xpath,"//a[@href='page.htm']").click Finds the item using XPath query.
Multiple Attributes click me click me => "click me", :index => 2).click You can combine more ways of finding elements. This example will click the second link with text click me.

No comments:

Post a Comment