我有一个包含3个复选框的html页面。每个文本框旁边都有一个文本。 复选框嵌套在div标签中 我想选中具有文字"清洁"
的复选框我的Xpath正在选择3个复选框 如何选择包含文本Clean的复选框? 它位于div标签内,id为id =" operations_edit_process_list_task_1"
我的Xpath是:
//div[@id="operations_edit_process_list_task_1"]//span[text()="Clean"]//following::span[@title="Turn group off or on."]/input[1]
HTML是:
<div id="operations_edit_process_list_task_1">
<span>
<span/>
<span>
<span title="Turn group off or on." style="">
<input type="checkbox" checked="" tabindex="-1"/>
</span>
</span>
<span/>
</div>
</div>
</div>
</div>
</div>
</div>
<div style="overflow: hidden; display: none;"/>
</div>
<div aria-selected="false" role="treeitem" aria-setsize="3" aria-posinset="2" aria-expanded="false" aria-level="1">
<div class="GJPPK2LBIF GJPPK2LBAG" style="padding-left: 0px;">
<div class="GJPPK2LBIF GJPPK2LBKF GJPPK2LBCG" style="padding-left: 16px;position:relative;" onclick="">
<div class="GJPPK2LBJF GJPPK2LBBG" style="left: 0px;width: 15px;height: 15px;position:absolute;">
<div class="GJPPK2LBLF">
<div style="padding-left: 22px;position:relative;zoom:1;">
<div style="left:0px;margin-top:-8px;position:absolute;top:50%;line-height:0px;">
<div>
<div id="operations_edit_process_list_task_2">
<span>
<span class="myinlineblock" title="Match"
style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;width:100%;">Match</span>
</span>
<span/>
<span>
<span title="Turn group off or on." style="">
<input class="" type="checkbox" checked="" tabindex="-1"/>
</span>
</span>
<span/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div aria-selected="false" role="treeitem" aria-setsize="3" aria-posinset="3" aria-expanded="false"
aria-level="1">
<div class="GJPPK2LBIF GJPPK2LBAG" style="padding-left: 0px;">
<div class="GJPPK2LBIF GJPPK2LBKF GJPPK2LBCG" style="padding-left: 16px;position:relative;" onclick="">
<div class="GJPPK2LBJF GJPPK2LBBG" style="left: 0px;width: 15px;height: 15px;position:absolute;">
<div class="GJPPK2LBLF">
<div style="padding-left: 22px;position:relative;zoom:1;">
<div style="left:0px;margin-top:-8px;position:absolute;top:50%;line-height:0px;">
<div>
<div id="operations_edit_process_list_task_3">
<span>
<span class="myinlineblock" title="PossMatch"
style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;width:100%;">PossMatch</span>
</span>
<span/>
<span>
<span title="Turn group off or on." style="">
<input class="" type="checkbox" checked="" tabindex="-1"/>
</span>
</span>
<span/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
谢谢, 里亚兹
答案 0 :(得分:1)
Xpath选择div id =“operations_edit_process_list_task_2”中的输入框并使用“Clean”文本:
"//div[@id='operations_edit_process_list_task_2'][.//span='Clean']//input"
或者:
"//div[@id='operations_edit_process_list_task_2' and contains(.,'Clean')]//input"