<<Previous Post << Complete Tutorial>> Next Post>
In the previous article, I have practically demonstrated last() XPath Function.
In this article, I am going to explain the next XPath Function known as position()
If there are n number of child tags under a parent tag, then to locate the child tag in a particular position among the other child tags, we can use postion() XPath Function.
Let’s get started.
Selenium Locators – postion() XPath Function
Follow the below steps for practicing the position() XPath Function:
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) Execute the Relative XPath Expression //p into the ‘ChroPath’ and observe that the two paragraphs are getting located as shown below:
4) Let’s locate the first paragraph p tag using the position() XPath Function in Relative XPath Expression.
Relative XPath Expression: //p[position()=1]
Execute the above Relative XPath Expression in the ‘ChroPath’ and observe that the first paragraph is getting located as shown below:
5) Let’s locate the second paragraph p tag using the position() XPath Function in Relative XPath Expression.
Relative XPath Expression: //p[position()=2]
Execute the above Relative XPath Expression in the ‘ChroPath’ and observe that the second paragraph is getting located as shown below:
6) 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:
7) Let’s find the first input tag in the above page using position() XPath Function:
Relative XPath Expression: (//input)[position=1]
Execute the above Relative XPath Expression in ChroPath and observe that the first input tag got located as shown below:
8) Let’s find the eight input tag in the above page using position() XPath Function:
Relative XPath Expression: (//input)[position=8]
Execute the above Relative XPath Expression in ChroPath and observe that the eight input tag got located as shown below:
Here concludes this article.
In the next article, I will start explaining the XPath AXES Concepts.
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>