HomeSelenium

Selenium Locators – parent XPath AXES

Selenium Locators – parent XPath AXES

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

In the previous articles, I have listed the different types of XPath Axes available and explained the following , preceding following-sibling and preceding-sibling XPath Axes.

In this article, I am going to explain the next XPath Axes i.e. parent.

parent XPath Axes select/locate the parent tag of the current tag in the HTML document.

Let’s get started with the practical demonstration of parent XPath Axes.

Selenium Locators – parent XPath AXES

Follow the below steps to practice parent XPath Axes along with me:

1) Open http://compendiumdev.co.uk/selenium/basic_web_page.html 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:

last() XPath Function - Website Launch

2) Open ChroPath in Chrome Browser where ‘Rel XPath’ is selected as shown below:

last() XPath Function - Rel XPath

3) Let’s first locate the ‘head’ tag in this page using the Relative XPath Expression //head

Execute the above XPath Expression in ChroPath and observe that the ‘head’ tag on the page got located as shown below:’

parent XPath AXES - head tag

4) Now using the above Relative XPath Expression and parent XPath Axes, let’s create the below Relative XPath expression to locate the ‘html’ parent tag of the ‘head’ tag.

//head/parent::html

Execute the above XPath Expression in ChroPath and observe that it is locating the html tag on the page as shown below:

parent XPath AXES - head parent

5) Now let’s locate the parent tag of ‘body’ tag using the below Relative XPath Expression having the parent XPath Axes:

//body/parent::html

Execute the above XPath Expression in ChroPath and observe that it is locating the html tag on the page as shown below:

parent XPath AXES - body html

6) Let’s locate the parent of ‘title’ tag using the below Relative XPath having parent XPath Axes.

//title/parent::head

Execute the above XPath Expression in ChroPath and observe that it is locating the head tag on the page as shown below:

parent XPath AXES - title head

7) Let’s locate the parent of ‘p’ tag using the below Relative XPath having parent XPath Axes.

//p/parent::body

Execute the above XPath Expression in ChroPath and observe that it is locating the body tag on the page as shown below:

parent XPath AXES - p body

Here concludes this article.

In the next article, I will start explaining the next XPath AXES – child

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