【发布时间】:2015-07-14 12:27:15
【问题描述】:
我正在尝试查找复选框的 Xpath,然后使用我的 Python Webdriver 脚本单击它。 该复选框位于表格的列中。复选框的文本在另一列中。 文字是 DM。我想单击具有文本值 DM 的复选框。 我不想要具有文本值 ceb07_14_1504_06_52 的复选框
我需要一些帮助来获取 Xpath。
HTML 是:
<table cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
<tr class="GAT4PNUFG" __gwt_subrow="0" __gwt_row="0">
<td class="GAT4PNUEG GAT4PNUGG GAT4PNUHG">
<div __gwt_cell="cell-gwt-uid-139" style="outline-style:none;" tabindex="0">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GAT4PNUEG GAT4PNUGG">
<div __gwt_cell="cell-gwt-uid-140" style="outline-style:none;">
<span class="linkhover" title="ceb07_14_1504_06_52" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">ceb07_14_1504_06_52</span>
</div>
</td>
<td class="GAT4PNUEG GAT4PNUGG">
<div __gwt_cell="cell-gwt-uid-141" style="outline-style:none;">
<span class="" title="Selenium Webdriver added datamap" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Selenium Webdriver added datamap</span>
</div>
</td>
<td class="GAT4PNUEG GAT4PNUGG GAT4PNUBH">
<div __gwt_cell="cell-gwt-uid-142" style="outline-style:none;">
<span class="" title="" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;"/>
</div>
</td>
</tr>
<tr class="GAT4PNUEH GAT4PNUMG" __gwt_subrow="0" __gwt_row="1">
<td class="GAT4PNUEG GAT4PNUFH GAT4PNUHG GAT4PNUNG">
<div __gwt_cell="cell-gwt-uid-139" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GAT4PNUEG GAT4PNUFH GAT4PNUNG">
<div __gwt_cell="cell-gwt-uid-140" style="outline-style:none;">
<span class="linkhover" title="DM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">DM</span>
</div>
</td>
<td class="GAT4PNUEG GAT4PNUFH GAT4PNUNG">
<td class="GAT4PNUEG GAT4PNUFH GAT4PNUBH GAT4PNUNG">
</tr>
</tbody>
</table>
我试过 //input[@type="checkbox" 和 tabindex="-1"] 我试过 //input[@type="checkbox"] 这并不好,因为表可能会随着数据的添加而增长。
我也试过了:
datamaps_checkbox_element = self.driver.find_element(By.XPATH, 'html/body/div[2]/div[2]/div/div[4]/div/div[2]/div/div[3]/div/div[5]/div/div[3]/div/div[4]/div/div[2]/div/div[4]/div/div[3]/div/div[2]/div/div/table/tbody/tr/td[1]/div/input')
datamaps_checkbox_element.click()
问候,里亚兹
【问题讨论】:
标签: python selenium xpath selenium-webdriver