Structure Dependency in Locator strategy

In this tutorial, we will discuss about the Structure Dependency in Locator strategy.

Type of Structure Dependency

Structure Dependency in Locator strategy is classified in two category

  • Structure based
  • Attribute based

Structure Based:

This is based on the structure of the web page. If you want to locate the element of the web page by following the structure of the web page, then you need to use the structure-based locators. Below are the examples of structure-based locators

  • XPath
  • DOM
  • CSS

Attribute based:

This is based on the attribute of the element of the web page. If you want to locate the element of the web page based on the attribute of the element, then you need to use the Attribute-based locators. Below are the examples of the Attribute-based locators.

From the above section you can notice that CSS locator is used by both structure based and attribute-based locators. It is very flexible and gives an awesome balance between using structure and attributes to find the elements. That’s why this is mostly used locator strategy to be followed.

The main strategy to use the locators is that you should consider the structure dependency before using the locators. Another thing you need to remember that if a locator matches multiple element of web page, Only the first element of the list will be return to WebElement Object variable. So if you need more than one element to be returned to the WebElement Object then you need to use findElements and return as a List / Set variable.

Leave a Reply

Your email address will not be published. Required fields are marked *