Sunday 13 April 2014

Locators in Selenium and tools for identifying them

Selenium is essentially a web automation tool where in the various UI elements of the web application under test are manipulated to drive the automation process. Hence identifying these UI elements is a prerequisite to creating automation scripts.

Selenium identifies these UI elements using what are known as locators. Locators tell selenium which UI element (say button, link, text box, drop down) to be targeted.

locator 01

Using proper locators selenium will be able to identify these UI elements.

locator02

Different browsers have different tools for analysing the various UI elements present within the web page.

Mozilla Firefox browser has the default Firefox developer toolbar for analysing HTML elements which can be turned on by using the shortcut SHIFT + F12 . But a more convenient tool that is most commonly used with Firefox is the Firebug toolbar. User can analyse a UI element either by
(i) directly right clicking on the element and selecting the option ‘Inspect Element with Firebug’
or
(ii) toggling on the firebug toolbar and using the inspect option to analyse the element.

locator03

Internet Explorer has an inbuilt developer toolbar which can be activated using the shortcut F12. This too like firebug has an inspect element capability which can be used for HTML element analysis.

locator IE

Google Chrome too has an inbuilt developer toolbar which can be used likewise.

locator chrome

There might be instances where certain web applications can be opened only from specific browsers such as IE or Chrome (other than Firefox). In such cases it would be very useful to know how to identify UI elements on these browsers as well.

Different types of Locators in Selenium

Selenium provides different types of locators for effectively identifying UI elements within a web page. The various locator types used within selenium are:

  • ID
  • Name
  • Link Text
  • CSS selector
  • DOM selector
  • XPath selector

No comments:

Post a Comment