In the previous article, I have listed the different types of XPath Axes available.
In this article, I am going to explain the first XPath Axes i.e. following.
following XPath Axes can select/traverse everything in the HTML document after the closing tag of the current node.
For example, if you are using ‘following’ XPath Axes with ‘head’ tag, then it can help you to select/traverse all the tags that come after the ending of ‘head’ tag (i.e. after </head> tag).
And in this example, the tags inside the <head> </head> say <title> etc. cannot be selected/traversed using the following XPath Axes.
All the tags that come after the </head> in this example, can be selected/traversed using the following.
Let’s get started with the practical demonstration of following XPath Axes.
Selenium Locators – following XPath AXES
Follow the below steps to practice following XPath Axes along with me:
2) Open ‘ChroPath’ functionality as shown below in the Chrome Browser:
3) Select ‘Rel XPath’ option from the ‘Selectors’ dropdown as shown below:
4) First, let’s locate the ‘head’ tag by executing the Relative XPath Expression //head in the ChroPath as shown below:
5) Now let’s try to locate ‘title’ tag which is inside the <head> …</head> by building the Relative XPath Expression as //head/following::title
Note: No elements will be located as the following XPath Axes can only be used for locating the tags that come after the </head> tag. Whereas <title> tag will come before the </head>.
Execute the above Relative Expression and observe that 0 elements (i.e. no elements got located) as shown below:
6) Now let’s try to locate ‘body’ tag which comes after the </head> tag by building the Relative XPath Expression as //head/following::body
Note: As body tag comes after the </head> tag, it will be located now as shown below:
7) Let’s find all the div tags after //body/div/div, by executing the Relative XPath Expression //body/div/div/following::div and observe that all the div tags which come after the </div> got located as shown below:
8) Let’s find the first div tag after //body/div/div, by executing the Relative XPath Expression //body/div/div/following::div and observe that the first div tag which come after the </div> got located as shown below:
9) Let’s find all the input tags after //body/div, by executing the Relative XPath Expression //body/div/following::input and observe that all the input tags which come after the </div> got located as shown below:
Here concludes this article.
In the next article, I will start explaining the next XPath AXES – preceding
- > 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.