如何使用跨度内的文本标识span的以下元素。在下面的代码中,我需要使用其文本识别第一个跨度,以便在<li>
中找到以下元素。我可以使用其class属性识别span,但我无法使用contains(text(), 'System stopped operation')
来识别span标记。我的想法是使用它的类识别第一个跨度,然后找到以下<li>
<span class="text-danger">
<img src="images/crit.gif" width="15" height="15" border="0" align="absbottom" alt="Critical Alarm" title="Critical Alarm">
System stopped operation
</span>
<ul>
<li>
The system is not in operation.</li>
</ul>
<span class="text-warning">
<img src="images/warn.gif" width="15" height="15" border="0"
align="absbottom" alt="Warning Alarm" title="Warning Alarm">
System restarted
</span>
<ul>
<li>
System has been restarted.</li>
</ul>
要根据相应<li>
标记中的文本标识<span>
元素,可以使用以下基于xpath的解决方案:
<li>
系统未运行:
//span[contains(., 'System stopped operation')]//following::ul[1]/li
<li>
:
//span[contains(., 'System restarted')]//following::ul[1]/li
如果你在SPAN
下寻找LI
或SPAN
,很难从这个问题中得知,所以这两者都是。
您可以使用下面的CSS选择器来查找SPAN
span.text-danger
或者下面的CSS选择器找到所需的LI
下的SPAN
span.text-danger + ul li