Unlike ID attributes, every element in a web page has a unique XPath. An XPath (XML Path Language) is a query language for selecting nodes from XML like documents, such as HTML in our case.
XPath is a major element in the XSLT standard. XPath can be used to navigate through elements and attributes in an XML document.
Important features of XPath XPath is a standard function: XPath provides a rich library of standard functions to manipulate string values, numeric values, date and time comparison, node and QName manipulation, sequence manipulation, Boolean values etc. Path is W3C recommendation.
In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes. XML documents are treated as trees of nodes. The topmost element of the tree is called the root element.
This answer is for XPath 1.0 where there is no equivalent of the XPath 2.0 standard ends-with() function.
The following XPath 1.0 expression selects all elements in the xml document, whose names end with the string "fu":
//*[substring(name(),string-length(name())-1) = 'fu']
Do something like:
//*[ends-with(name(), 'fu')]
For a good XPath reference, check out W3Schools.
I struggled with Dimitre Novatchev's answer, it wouldn't return matches. I knew your XPath must have a section telling that "fu" has length 2.
It's advised to have a string-length('fu') to determine what to substring.
For those who aren't able to get results with his answer and they require solution with xpath 1.0:
//*[substring(name(), string-length(name()) - string-length('fu') +1) = 'fu']
Finds matches of elements ending with "fu"
or
//*[substring(name(), string-length(name()) - string-length('Position') +1) = 'Position']
Finds matches to elements ending with "Position"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With