In this article, I am going to practically demonstrate the usage of Link Text locators for locating the UI elements on the Web Pages.
Link Test locators are used to locate Hyperlink UI elements on the Web Pages.
Let’s get started.
Locators for Selenium – Demonstrating Link Text Locator
Follow the below steps for locating the Hyperlink UI elements on the Web Pages using Link Text Locator:
1) Install Selenium IDE, if not installed in your chrome browser (Refer steps to install Selenium IDE in your chrome browser)
2) Navigate to http://omayo.blogspot.com/ in your chrome browser as shown below:
3) Right click on the ‘Page One’ hyperlink and select ‘Inspect’ option as shown below:
4) Observe that the HTML code related to the ‘Page One’ hyperlink got highlighted as shown below:
5) Observe that the above-highlighted HTML code has the text between the <a> and </a> tags. We can use this text as a link text locator for locating the ‘Page One’ hyperlink on the Web Page. Lets double click on the text between <a> and </a> tags, right-click and select ‘Copy’ option as shown below:
6) Launch Selenium IDE from Chrome Browser by following the steps provided in below article:
7) Enter any Selenium IDE command say ‘Click’ into the ‘Command’ Text box field as shown below:
Note: Without entering this command ‘Find target in Page’ magnifier icon option will be in a disabled state by default and will be enabled only after entering any command into the ‘Command’ text box field as shown below:
8) Now, type link= into the Target text box field as shown below:
9) Paste the text between the anchor tags <a> and </a>, copied earlier (i.e. in Step 5) into the ‘Target’ Text box field and click on ‘Find target in Page’ search icon option as shown below:
10) Observe that the ‘Page One’ hyperlink on the Web Page got highlighted for a second on clicking the ‘Find target in Page’ option in the above step using the link=Page One locator provided in the Target field as shown below:
As the ‘Page One’ hyperlink is getting highlighted using the link text locator (i.e. link=Page One) provided in Selenium IDE, we can confirm that the give link text locator is able to locate the hyperlink using the text between the anchor tags (i.e. <a> and </a>).
Hence in this example, we have used the link text locator (i.e. link=Page One) for locating the hyperlink on the Web Page having the text between the anchor tags as ‘Page One’/.
In the next article, I will demonstrate the next locator i.e. CSS Selector locators for locating the UI elements on the Web Page.
- > 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 ?
On a mission to contribute to the Software Testing Community in all possible ways.