鉴于 HTML 包含:
<div tagname="779853cd-355b-4242-8399-dc15f95b3276_Destination" class="panel panel-default"></div>
我们如何在 XPath 中编写以下表达式:
查找 <div>
tagname
的元素属性以字符串“Destination”结尾
我已经搜索了好几天,但我无法找到有用的东西。其中,我试过例如:
div[contains(@tagname, 'Destination')]
最佳答案
XPath 2.0
//div[ends-with(@tagname, 'Destination')]
XPath 1.0
//div[substring(@tagname, string-length(@tagname)
- string-length('Destination') + 1) = 'Destination']
关于html - XPath 测试该字符串以子字符串结尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40934644/