HomeSelenium

Locators for Selenium – Demonstrating XPath Expression Locator

Locators for Selenium – Demonstrating XPath Expression Locator

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

In the previous articles, I have explained what are locators? and Different types of locators.

In this article, I am going to practically demonstrate the usage of XPath Expression locators for locating the UI elements on the Web Pages.

Note: This article is just for demonstrating XPath at a high level. XPath will be explained in detail in the upcoming articles.

Let’s get started.

Locators for Selenium – Demonstrating XPath Expression Locator

Follow the below steps for locating the UI elements on the Web Pages using XPath Expression 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:

Locators for Selenium - Navigate to Omayo in Chrome

 

3) Right click on the ‘ClickToGetAlert’ button and select ‘Inspect’ option as shown below:

XPath Expressions Locators - Inspect

4) Observe that the HTML code related to the ‘ClickToGetAlert’ button got highlighted as shown below:

XPath Expressions Locators - Code

5) Right click on the above-highlighted HTML line and select ‘Copy’ > ‘Copy XPath’ option as shown below:

XPath Expressions Locators - Copy XPath

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:

Locate using Link Text - Command

8) Now, type xpath= into the Target text box field as shown below:

XPath Expressions Locators - XPath Equals

9) Paste the XPath Expression 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:

XPath Expressions Locators - Pasted XPath

 

10) Observe that the ‘ClickToGetAlert’ button on the Web Page got highlighted for a second on clicking the ‘Find target in Page’ option in the above step using the xpath=//*[@id=”alert1″] locator provided in the Target field as shown below:

XPath Expressions Locators - Located

As the ‘ClickToGetAlert’ button got highlighted using the XPath Expression locator (i.e. xpath=//*[@id=”alert1″]) provided in Selenium IDE, we can confirm that the give XPath Expression locator is able to locate the ‘ClickToGetAlert’ using its HTML code’s XPath Expression.

Hence in this example, we have used the XPath Expression locator (i.e. xpath=//*[@id=”alert1″]) for locating the ‘ClickToGetAlert’ button on the Web Page. 

In the next article, I will demonstrate the next locator i.e. DOM locator for locating the UI elements on the Web Page.

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 (0)

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