HomeSelenium

Selenium – Locators Priority

Selenium – Locators Priority

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

In the previous articles, I have explained the following:

In this article, I am going to explain the priority of locators.

As we can use more than one locators for locating a single UI element on the web page, we need to choose only one based on its priority.

Example: For locating, ‘Button2’ button on the http://omayo.blogspot.com/, we can use any of the below locators:

  1. ID Locator – id=but2
  2. CSS Selector – css=#but2
  3. XPath Expression – xpath=//input[@id=’but2′]
  4. DOM Locator – dom=document.getElementById(“but2”)

But, at the end we need to choose only one locator out of all the above possible locators based on their priority.

Let’s get started.

Selenium – Locators Priority

The following diagram depicts the priority of locators:

Priority of Locators

Let’s understand the above diagram using the below points:

  • > The high priority starts from left to right in the above image
  • > First Priority goes for ID locator
  • > If there is no ID locator for the given UI element, we can go for the next priority locator i.e. Name locator
  • > If there is no ID or Name locator for the given UI element, we can go for the next priority locator i.e. Class Name locator
  • > If there is no ID, Name or Class Name locator for the given UI element, we can go for the next priority locator i.e. Link Text locator
  • > If there is no ID, Name, Class Name or Link Text locator for the given UI element, we can go for the next priority locator i.e. CSS Selector Locator
  • > If there is no ID, Name, Class Name or Link Text locator for the given UI element and also we are unable to create a CSS Selector for locating the given UI element, we can go for XPath Locator
  • > 99.99% of cases, we will be able to locate with XPath locator. In rare and not possible cases, we will go for the final DOM locator. Hence DOM locator has the last priority out of all the locators for Selenium.

With this article, we are done with all the basic concepts required to understand Locators.

From the next article, I am going to explain the XPath Expression Locators in detailed and step by step manner.

Next Steps:

  • > To learn more about Selenium, continue to the next post (Click on Next Post link below)
  • > Check complete Selenium Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Arun Motoori

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

Comments (2)

Leave a Reply

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

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp