I have a webpage with three elements <input>that have the same attribute name. Ideally, I would like to select the second of these elements, except that there is only one element on the page, and I want to select this element instead.
Ideally, I would like something like (pseudocode, since it maxdoes not exist)
(//input[@name='myname'])[max(1, last()-1)]
I thought that maybe I could do something like the following, except that it gives all three elements
(//input[@name='myname'])[last()-1 or 1]
What is the best way to accomplish this using XPath?
Suver source
share