【发布时间】:2016-07-03 22:02:01
【问题描述】:
我在单击一个元素后显示了一个对话框。在此对话框中有 2 个表格 (HTML)。表中的表。 表 1 有文本“匹配审计代码” 表 2 有一些行和列。 第 1 列有一个复选框。 第 2 列有一个 char 值,例如字母“我”) 第 3 列有一些文字,例如“匹配到完整地址”
我想从第 1 列找到复选框,该复选框具有文本描述“与完整地址匹配”,并且父表具有文本“匹配审核代码”
我尝试了以下 Xpath,它找到了带有“匹配到完整地址”文本的复选框
//div[contains(text(), "Matched to full address")]/ancestor::tr[1]/td[1]//input
我的 Selenium Python 脚本不会点击此复选框。开发人员说,HTML 中的某处可能有超过 1 个“匹配到完整地址”。
我需要 Xpath 从具有文本“匹配审核代码”的父表开始,然后向下到下一个表 其中有文本“匹配到完整地址”,然后找到复选框。
请问我该如何构建 Xpath?
HTML 是:
<table class="GJPPK2LBAL" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<div class="GJPPK2LBPK">Match audit codes</div>
</td>
<td align="left" style="vertical-align: top;">
<button class="gwt-Button GJPPK2LBLK" type="button">X</button>
</td>
</tr>
</tbody>
</table>
<table class="GJPPK2LBOK" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" style="vertical-align: middle;">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<tr>
<td align="left" style="vertical-align: top;">
<div style="overflow: auto; position: relative; width: 25em;">
<div style="position: relative;">
<table class="GJPPK2LBJE" cellspacing="0"
__gwtcellbasedwidgetimpldispatchingfocus="true"
__gwtcellbasedwidgetimpldispatchingblur="true">
<thead aria-hidden="false">
<colgroup>
<tbody>
<tr class="GJPPK2LBCD" __gwt_subrow="0" __gwt_row="0">
<td class="GJPPK2LBBD GJPPK2LBDD GJPPK2LBED">
<div __gwt_cell="cell-gwt-uid-5972" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBBD GJPPK2LBDD">
<div __gwt_cell="cell-gwt-uid-5973" style="outline-style:none;">I</div>
</td>
<td class="GJPPK2LBBD GJPPK2LBDD GJPPK2LBOD">
<div __gwt_cell="cell-gwt-uid-5974" style="outline-style:none;">Matched to
full address
</div>
</td>
</tr>
<tr class="GJPPK2LBCE" __gwt_subrow="0" __gwt_row="1">
<td class="GJPPK2LBBD GJPPK2LBDE GJPPK2LBED">
<div __gwt_cell="cell-gwt-uid-5972" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBBD GJPPK2LBDE">
<div __gwt_cell="cell-gwt-uid-5973" style="outline-style:none;">B</div>
</td>
<td class="GJPPK2LBBD GJPPK2LBDE GJPPK2LBOD">
<div __gwt_cell="cell-gwt-uid-5974" style="outline-style:none;">Matched to
building
</div>
</td>
</tr>
<tr class="GJPPK2LBCD" __gwt_subrow="0" __gwt_row="2">
<tr class="GJPPK2LBCE" __gwt_subrow="0" __gwt_row="3">
</tbody>
<tbody style="display: none;">
<tfoot style="display: none;" aria-hidden="true"/>
</table>
谢谢, 里亚兹
【问题讨论】:
标签: python-2.7 selenium xpath selenium-webdriver