Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath testing that string ends with substring?

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')]
like image 312
Happy Bird Avatar asked Dec 02 '16 14:12

Happy Bird


People also ask

How do you write the end of XPath?

XPath Ends-with. Using “OR” Statement. Using “AND” Statement.

What is substring in XPath?

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.

What does * indicate in XPath?

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.


Video Answer


2 Answers

XPath 2.0

//div[ends-with(@tagname, 'Destination')]

XPath 1.0

//div[substring(@tagname, string-length(@tagname) 
                          - string-length('Destination') + 1)  = 'Destination']
like image 96
kjhughes Avatar answered Oct 27 '22 08:10

kjhughes


You can use ends-with (Xpath 2.0)

//div[ends-with(@tagname, 'Destination')]
like image 6
Ievgen Avatar answered Oct 27 '22 09:10

Ievgen