HomeSelenium

Selenium – More details about Name, Class Name and Link Text Locators

Selenium – More details about Name, Class Name and Link Text Locators

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

In our previous articles, I have demonstrated the below:

In this article, I am going to explain more details about Name, Class Name, and Link Text Locators.

Let’s get started.

Selenium – More details about Name, Class Name, and Link Text Locators

Following are the different points, which will help you in understanding the Name, Class Name and Link Text Locators in detail:

Name Locator:

1) name attribute value of the element in the HTML code will be used as Name Locator to find the UI element on the web page. Refer Demonstration of Name locator in a practical way

2) name locator is the second preferred or priority locator for locating the UI elements on the web page.

3) More than one element on the web page can have the same name locator. Developers are allowed to give the same name to multiple UI elements on the page as per the standards or development practices.

Let me give a practical example stating the above:

Open http://omayo.blogspot.com/ in the Chrome browser and right click on the ‘Male’ and ‘Female’ radio options separately to find the name attribute value of both as shown below:

Other locators - Same Name Attibute values

The above screenshot proves that more than one UI element can have the same name attribute value and it is as per the development standards/process.

When you have two UI elements having the same name locator, the name locator will only select the first UI element (Say Male radio option in the above example) and won’t locate the second UI element (Say Female radio option in the above example) as shown below:

Other locators - Male

In order to locate the second radio option (say Female radio option in the above example), we have to use a different locator type. Will be explaining this in the upcoming articles.

Class Name Locator:

1) class attribute value of the element in the HTML code will be used as Class Name Locator to find the UI element on the web page. Refer Demonstration of Class Name locator in a practical way

2) Class Name locator is the third preferred or priority locator for locating the UI elements on the web page.

3) More than one element on the web page can have the same class name locator. Developers are allowed to give the same class name to multiple UI elements on the page as per the standards or development practices.

Let me give a practical example stating the above:

Open http://omayo.blogspot.com/ in the Chrome browser and right click on the two different text box fields separately to find the class name attribute value of both as shown below:

Other locators - Same Class Names

The above screenshot proves that more than one UI element can have the same class name attribute values and it is as per the development standards/process. It’s very common to have the same class attribute value for most of the UI elements on the web pages.

When you have two or more than two UI elements having the same class name locator, the name locator will only select the first UI element (Say first text box field in the above example) and won’t locate the second UI element (Say second text box field in the above example). Demonstration of Class Name locator is not possible in Selenium IDE, hence I will be covering this in the future articles of Selenium WebDriver.

Link Text Locators:

1) The text inside the anchor tags <a> ..</a> of the hyperlink element in the HTML code will be used as Link Text Locator to find the Hyperlink UI element on the web page. Refer Demonstration of Link Text locator in a practical way

2) Link Text locator is the fourth preferred or priority locator for locating the Hyperlink UI elements on the web page.

3) More than one hyperlink element on the web page can have the Link Text.

Let me give a practical example stating the above:

Open http://omayo.blogspot.com/ in the Chrome browser and right click on the two different links separately to find the text between the <a> and </a> tags of them as shown below:

Other locators - Two Anchors

The above screenshot proves that more than one Hyperlink UI element can have the same Text between the <a> ..</a> tags.

When you have two or more than two UI elements having the text between the anchor tabs of Hyperlink elements, the link text locator will only select the first Hyperlink UI element (Say first Hyperlink in the above example) and won’t locate the second Hyperlink UI element (Say the second Hyperlink having the same text between <a> tags in the above example) as shown below:

Other locators - First LinkHope this article has given you enough information on Name, Class Name and Link Text Locators and their different aspects.

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>>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

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