86. position() function in XPath Expressions (Selenium Java 2026)

Published: 16 May 2026
on channel: QAFox
59
1

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.


On this page of the site you can watch the video online 86. position() function in XPath Expressions (Selenium Java 2026) with a duration of hours minute second in good quality, which was uploaded by the user QAFox 16 May 2026, share the link with friends and acquaintances, this video has already been watched 59 times on youtube and it was liked by 1 viewers. Enjoy your viewing!