position() XPath Function
position() is an optional XPath function
It returns the position of a node within a node-set (starting from 1)
Practical Demonstration
//p[1] selects the first p element
//p[position()=1] same as above
//p[2] selects the second p element
//p[position()=2] same as above
(//input)[1] selects the first input element
(//input)[position()=1] same as above
Key Point:
Using [n] is shorthand for [position()=n] in XPath.
Download
0 formats
No download links available.
86. position() function in XPath Expressions (Selenium Java 2026) | NatokHD