Given that the HTML contains:
<div tagname="779853cd-355b-4242-8399-dc15f95b3276_Destination" class="panel panel-default"></div>
How do we write the following expression in XPath:
Find a <div>
element whose tagname
attribute ends with the string 'Destination'
I've been searching for days and I can't come up with something that works. Among many, I tried for example:
div[contains(@tagname, 'Destination')]
XPath Ends-with. Using “OR” Statement. Using “AND” Statement.
What is Xpath substring? In Xpath, the substring is case-sensitive which returns the function of the given input string that is executed before the first occurrence which is executed before the upcoming argument. The function has been executed in the Xpath string function list.
xpath=//tag[@attribute='value'] // : Select current node. tag: Tagname of the particular node. Also, "*" is for searching any tag in the xml structure. @: Select attribute.
//div[ends-with(@tagname, 'Destination')]
//div[substring(@tagname, string-length(@tagname)
- string-length('Destination') + 1) = 'Destination']
You can use ends-with
(Xpath 2.0)
//div[ends-with(@tagname, 'Destination')]
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