Oct 29, 2018

Different types of locator in Selenium IDE

Locators tell Selenium IDE which GUI elements such as Text Box , Buttons, Checkboxes etc its needs to operate on.  Identification of correct GUI elements is a prerequisite to  create an automation script.  But accurate identification of GUI elements is more difficult than it sounds. Selenium provides a number of Locators to precisely locate a GUI element
The different types of locator are:

  • ID
  • Name
  • Link Text
  • CSS Selector
    •  Tag and ID
    •  Tag and class
    •  Tag and attribute
    • Tag, class, and attribute
    • Inner text
  •  DOM (Document Object Model)
    •  getElementById
    •  getElementsByName
    •  dom:name
    •  dom:index
  • XPath

Whenever possible, it is strongly recommended to stay away from using unstable element locators such as xpaths to target elements
on the page. Xpaths are considerably fragile because minimal changes in the structure of the HTML document could render current targeting queries
invalid. In environments where the structure of the HTML document changes frequently, keeping track of elements using XPaths can become
a maintenance nightmare.

CSS Selectors are strongly recommended over Xpaths.

In general, your choice of element locators should also not be based on textual content in the HTML document, whenever it is possible for you to avoid it.

Rather, it should be based on element identifiers, unique attribute values or other structural information that is stable enough to withstand frequent changes to the web application without breaking the queries used to look up the elements.