HomeSelenium

Selenium Locators – text() XPath Function

Selenium Locators – text() XPath Function

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

In the previous article, I have explained the different XPath functions.

In this article, I am going to practically demonstrate the first XPath function i.e. text() function.

Let’s get started.

Selenium Locators – text() XPath Function

Follow the below steps for practicing the text() XPath function along with me:

1) Open http://omayo.blogspot.com/ in Chrome Browser, where ChroPath is already installed (Refer ChroPath installation in Chrome Browser here and its usage in Chrome Browser here ) as shown below:

Relative XPath - More complex application

2) Open ‘ChroPath’ functionality as shown below in the Chrome Browser:

Relative XPath - ChroPath

3) Select ‘Rel XPath’ option from the ‘Selectors’ dropdown as shown below:

4) Let’s locate the below text using the text() XPath function.

Selenium Locators - locate this one

Right click on the above text element and select ‘Inspect’ option as shown below:

Selenium Locators - Inspect

From the below HTML code that got highlighted on inspection, copy the text between the start and end tags as shown below:

Selenium Locators - highlighted text copy

Now using the above-highlighed HTML code, let’s create a Relative XPath Expression using the text() function as shown below:

Note: Use the above-copied text as a value to the text() function in the below XPath:

//p[text()=’PracticeAutomationHere‘]

Let’s execute the above Relative XPath Expression having text() function in ChroPath and observe that it is locating the above-inspected element on the page as shown below:

Selenium Locators - paragraph located

5) In place of the text() function in above Relative XPath Expression, we can also use the dot operator ( . ) as shown below:

//p[.=’PracticeAutomationHere‘]

Let’s execute the above Relative XPath Expression having text() function in ChroPath and observe that it is locating the above-inspected element on the page as shown below:

Selenium Locators - dot locator

Hence you can use text() and dot (. ) interchangeable for locating the UI element using their text.

In the next article, I will practically demonstrate the contains() XPath function.

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