Monday 14 April 2014

Identifying UI elements using ID, Name, Link text locators

Among the various types of locator strategies used in selenium, locating elements using the id, name or link text locator strategy is the most simplest and direct method. All locators are given in the format locatorType = location where ‘locatorType’ is the location strategy followed by the location of the element.

Locating by ID

Locating using ID is the most common way of locating UI elements since all id’s on a pages must be unique (assuming your web application adheres to this W3C specification; although this is not followed mostly).

Locator format: id = ‘id of the element’

Example: For identifying the Google search text box, one could inspect its id attribute using Firebug.

locating by ID

Once we know the id value, entering this “id=gs_tti0” in the proper format in the target field of the selenium IDE and clicking the find button will allow us to locate the text box.

locator id IDE_

Locating by Name

Locating elements using the name locator is similar to id, the only difference being the id locatorType is replaced using the name locatorType.

Locator format: name = ‘name of the element’

Example: The name locator strategy can be demonstrated by trying to identify the Google search button.

locating by name firebug

Now entering “name = btnK” in the selenium IDE target field and clicking find would allow the user to locate the Google search button.

locating by name ide

Locating by Link text

Locating by link text strategy is also similar to the above two strategies. The difference being the change in the locatorType to ‘link’

Locator Format: link = ‘link text’

We shall demonstrate this by trying to locate one of the links present on the Google search page.

locating by link firebug

Now use “link = Hindi” in target field of IDE and find the link.

locating by link IDE

No comments:

Post a Comment