是否可以向 xpath 添加 maybee 子句?
Is it possible to add a maybee clause to a xpath?
如标题所示,是否可以向 xpath 添加可选定位器?
假设我有一个像这样的html结构
<div>
<h2>Some Text</h2>
<h2><span>Some Text</span></h2>
</div>
现在,我希望能够 select 两个包含文本 "Some Text" 的 h2 标签,因此对于 expamle //div//h2[text() ='Some Text']
只会产生第一个。是否可以通过某种方式向 xpath 添加可选参数,例如 //div//h2/?span[text() ='Some Text']
或其他东西。
尽量避免选择文本节点:通常最好使用元素节点的字符串值。在这种情况下
//h2[. = "Some Text"]
做你想做的。
如标题所示,是否可以向 xpath 添加可选定位器?
假设我有一个像这样的html结构
<div>
<h2>Some Text</h2>
<h2><span>Some Text</span></h2>
</div>
现在,我希望能够 select 两个包含文本 "Some Text" 的 h2 标签,因此对于 expamle //div//h2[text() ='Some Text']
只会产生第一个。是否可以通过某种方式向 xpath 添加可选参数,例如 //div//h2/?span[text() ='Some Text']
或其他东西。
尽量避免选择文本节点:通常最好使用元素节点的字符串值。在这种情况下
//h2[. = "Some Text"]
做你想做的。