<td>
<a>SAMPLE</a>
<div>
<small>Phase:
Planning >>
<a>Performance</a>
</small>
</div>
</td>
我正在试图定位上面带有“阶段:规划>>性能”文本的元素,但一直没有成功。
尝试使用:
//*[text()[contains(normalize-space(.),'Phase: Planning >> Performance')]]
目前存在的其他三个答案都不能完全满足您的要求。
以下是一些XPath表达式,可以实现您的要求:
You can select the small
elements whose normalized string
value is Phase: Planning >> Performance
via this XPath:
//small[normalize-space() = 'Phase: Planning >> Performance']
You can select all elements, regardless of name whose normalized string values equals the targeted string:
//*[normalize-space() = 'Phase: Planning >> Performance']
but this will select not only small
but also div
because both
have a string value equal to Phase: Planning >> Performance
.
You can select only the lowest element in the hierarchy, regardless of name whose normalized string values equals the targeted string:
//*[ normalize-space() = 'Phase: Planning >> Performance' and
not(.//*[normalize-space() = 'Phase: Planning >> Performance'])]
请尝试以下:
//small[contains(.,'Phase:')]
<span>Planning >></span>
试试这段代码
文本 Phase: Planning >>
和 Performance
属于两个不同的元素。
要定位 Phase: Planning >>
元素,您可以使用
//small[contains(text(),'Phase:')]
并定位到Performance
元素
//a[contains(text(),'Performance')]
Phase: Planning >> Performance
的文本。