gpt4 book ai didi

css - Selenium XPATH 或 CSS 从 html 表中选择一个带有指定文本的复选框 我选择了两个复选框

转载 作者:太空宇宙 更新时间:2023-11-04 02:48:08 24 4
gpt4 key购买 nike

我正在尝试从 HTML 列表中选择一个复选框。我想选中包含文本“USN”的复选框
我的 XPATH 正在选择 2 个复选框:

  • 美国海军
  • 美国海军日期

我想选中第一个复选框:

  • 美国海军

我的 XPATH 是:

//table[@id="reporting_add_report_tab_manual_ct_fields_avail"]//div[contains(text(), "USN")]/preceding::td[1]//input

我如何构建我的 XPATH 或 CSS 来选择我想要的确切复选框?此外,如果结构发生变化,XPATH 或 CSS 是可靠的。

HTML 是:

<table id="reporting_add_report_tab_manual_ct_fields_avail" class="GLKP2TGBJE" cellspacing="0" __gwtcellbasedwidgetimpldispatchingfocus="true" __gwtcellbasedwidgetimpldispatchingblur="true">
<thead aria-hidden="false">
<colgroup>
<tbody style="">
<tr class="GLKP2TGBCD GLKP2TGBJD" __gwt_subrow="0" __gwt_row="0">
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBED GLKP2TGBKD">
<div __gwt_cell="cell-gwt-uid-500" style="outline-style:none;">
<input type="checkbox" tabindex="-1" />
</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBKD">
<div __gwt_cell="cell-gwt-uid-501" style="outline-style:none;">USN</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBOD GLKP2TGBKD">
<div __gwt_cell="cell-gwt-uid-502" style="outline-style:none;" />
</td>
</tr>
<tr class="GLKP2TGBCE" __gwt_subrow="0" __gwt_row="1">
<td class="GLKP2TGBBD GLKP2TGBDE GLKP2TGBED">
<div __gwt_cell="cell-gwt-uid-500" style="outline-style:none;">
<input type="checkbox" tabindex="-1" />
</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDE">
<div __gwt_cell="cell-gwt-uid-501" style="outline-style:none;">DATASET</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDE GLKP2TGBOD">
<div __gwt_cell="cell-gwt-uid-502" style="outline-style:none;" />
</td>
</tr>
<tr class="GLKP2TGBCD" __gwt_subrow="0" __gwt_row="2">
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBED">
<div __gwt_cell="cell-gwt-uid-500" style="outline-style:none;">
<input type="checkbox" tabindex="-1" />
</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDD">
<div __gwt_cell="cell-gwt-uid-501" style="outline-style:none;">ID</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBOD">
<div __gwt_cell="cell-gwt-uid-502" style="outline-style:none;" />
</td>
</tr>
<tr class="GLKP2TGBCE" __gwt_subrow="0" __gwt_row="3">
<td class="GLKP2TGBBD GLKP2TGBDE GLKP2TGBED">
<div __gwt_cell="cell-gwt-uid-500" style="outline-style:none;">
<input type="checkbox" tabindex="-1" />
</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDE">
<div __gwt_cell="cell-gwt-uid-501" style="outline-style:none;">MATCH_AUDIT</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDE GLKP2TGBOD">
<div __gwt_cell="cell-gwt-uid-502" style="outline-style:none;" />
</td>
</tr>
<tr class="GLKP2TGBCD" __gwt_subrow="0" __gwt_row="4">
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBED">
<div __gwt_cell="cell-gwt-uid-500" style="outline-style:none;">
<input type="checkbox" tabindex="-1" />
</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDD">
<div __gwt_cell="cell-gwt-uid-501" style="outline-style:none;">EXPANDED_MATCH_AUDIT</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBOD">
<div __gwt_cell="cell-gwt-uid-502" style="outline-style:none;" />
</td>
</tr>
<tr class="GLKP2TGBCE" __gwt_subrow="0" __gwt_row="5">
<td class="GLKP2TGBBD GLKP2TGBDE GLKP2TGBED">
<div __gwt_cell="cell-gwt-uid-500" style="outline-style:none;">
<input type="checkbox" tabindex="-1" />
</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDE">
<div __gwt_cell="cell-gwt-uid-501" style="outline-style:none;">INTERNAL_ID</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDE GLKP2TGBOD">
<div __gwt_cell="cell-gwt-uid-502" style="outline-style:none;" />
</td>
</tr>
<tr class="GLKP2TGBCD" __gwt_subrow="0" __gwt_row="6">
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBED">
<div __gwt_cell="cell-gwt-uid-500" style="outline-style:none;">
<input type="checkbox" tabindex="-1" />
</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDD">
<div __gwt_cell="cell-gwt-uid-501" style="outline-style:none;">USN_DATE</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDD GLKP2TGBOD">
<div __gwt_cell="cell-gwt-uid-502" style="outline-style:none;" />
</td>
</tr>
<tr class="GLKP2TGBCE" __gwt_subrow="0" __gwt_row="7">
<td class="GLKP2TGBBD GLKP2TGBDE GLKP2TGBED">
<div __gwt_cell="cell-gwt-uid-500" style="outline-style:none;">
<input type="checkbox" tabindex="-1" />
</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDE">
<div __gwt_cell="cell-gwt-uid-501" style="outline-style:none;">VERSION</div>
</td>
<td class="GLKP2TGBBD GLKP2TGBDE GLKP2TGBOD">
<div __gwt_cell="cell-gwt-uid-502" style="outline-style:none;" />
</td>
</tr>
<tr class="GLKP2TGBCD" __gwt_subrow="0" __gwt_row="8">
<tr class="GLKP2TGBCE" __gwt_subrow="0" __gwt_row="9">
<tr class="GLKP2TGBCD" __gwt_subrow="0" __gwt_row="10">
</tbody>
<tbody style="display: none;">
<tfoot style="display: none;" aria-hidden="true" />

谢谢,里亚兹

最佳答案

//*[text() = 'USN']

这个 xpath 可以工作,但是这个是一个很长的查询。尝试使用 text()= 'USN' this 和你的而不是 contains。

关于css - Selenium XPATH 或 CSS 从 html 表中选择一个带有指定文本的复选框 我选择了两个复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33498868/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com