<<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 ,preceding-sibling, and parent XPath Axes.
In this article, I am going to explain the next XPath Axes i.e. child.
child XPath Axes select/locate the child tags of the current tag in the HTML document.
Let’s get started with the practical demonstration of child XPath Axes.
Selenium Locators – child XPath AXES
Follow the below steps to practice child 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:
2) Open ChroPath in Chrome Browser where ‘Rel XPath’ is selected as shown below:
3) Let’s first locate the ‘html’ tag in this page using the Relative XPath Expression //html
Execute the above XPath Expression in ChroPath and observe that the ‘html’ tag on the page got located as shown below:
6) Now using the above Relative XPath Expression and child XPath Axes, let’s create the below Relative XPath expression to locate the ‘head’ child tag of the ‘html’ tag.
//html/child::head
Execute the above XPath Expression in ChroPath and observe that it is locating the head tag on the page as shown below:
7) Now using the above Relative XPath Expression and child XPath Axes, let’s create the below Relative XPath expression to locate the ‘body’ child tag of the ‘html’ tag.
//html/child::body
Execute the above XPath Expression in ChroPath and observe that it is locating the body tag on the page as shown below:
8) Now using the above Relative XPath Expression and child XPath Axes, let’s create the below Relative XPath expression to locate the ‘title’ child tag of the ‘head’ tag.
//head/child::title
Execute the above XPath Expression in ChroPath and observe that it is locating the title tag on the page as shown below:
9) Now using the above Relative XPath Expression and child XPath Axes, let’s create the below Relative XPath expression to locate the ‘p’ child tags of the ‘body’ tag.
//body/child::p
Execute the above XPath Expression in ChroPath and observe that it is locating the p tags on the page as shown below:
Here concludes this article.
In the next article, I will start explaining the next XPath AXES – ancestor
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 ?
On a mission to contribute to the Software Testing Community in all possible ways.
<<Previous Post << Complete Tutorial>> Next Post>