Selenium 使用xpath中的其他文本定位页面中的文本
如何通过selenium中的xpath使用另一行中另一个span中的其他文本在一行中的span中定位某些文本,我不想通过html标记进行遍历,因为html模板可以动态更改,而且我没有唯一的Id 以下是我的代码,突出显示的文本为问答文本:-Selenium 使用xpath中的其他文本定位页面中的文本,selenium,xpath,Selenium,Xpath,如何通过selenium中的xpath使用另一行中另一个span中的其他文本在一行中的span中定位某些文本,我不想通过html标记进行遍历,因为html模板可以动态更改,而且我没有唯一的Id 以下是我的代码,突出显示的文本为问答文本:- <div id="surveyquescontent"> <table width="100%" cellspacing="0" cellpadding="0" border="0"> <tbody>
<div id="surveyquescontent">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<span class="mrQuestionText" style="">**Have you chosen your own date for when your electric bill is due?**</span>
</td>
</tr>
<tr>
<td>
<span style="">
<span class="mrQuestionTable" style="display:block;margin-left: 1em;">
<span id="Cell.0.0" style="">
<label for="_Q1_C0">
<span class="mrSingleText" style="">**Yes**</span>
</label>
</span>
</span>
</span>
</td>
</tr>
</tbody>
</table>
</div>
**您是否选择了自己的电费到期日期**
**对**
您可以尝试选择正确的
并使用以下兄弟::tr
继续挖掘到所需的
,例如:
//tr[.//span[@class='mrQuestionText']]
/following-sibling::tr[1]
//span[@class='mrSingleText']
在上面的示例中,我使用class
属性值来获得正确的
,如果必须,您可以轻松地将其更改为在
中使用文本,或者同时使用文本和类:
//tr[.//span[
@class='mrQuestionText'
and
.='Have you chosen your own date for when your electric bill is due?'
]]
/following-sibling::tr[1]
//span[@class='mrSingleText']