gpt4 book ai didi

python-2.7 - Selenium Python XPATH具有行和列的表如何从col1中选择名称为col2和col5的复选框

转载 作者:行者123 更新时间:2023-12-03 08:19:16 28 4
gpt4 key购买 nike

我有6列和一些行的表。对于第1行,Col0有一个复选框。第2列的文本为“名称”,第5列的文本为“ CRM”
第2行第2行的文字为“地址”,文字为“ CRM”
第7行第2行的文本为“名称”,第5行的文本为“ ESCR”
这种模式随着日期的行继续进行。

我想从col0中选中复选框,其中col2具有文本“名称”,col5具有文本“ CRM”

请问如何使用XPATH?

我已经开始了,可以从col5识别文本“ CRM”。我需要获取正确的行,因此需要找到“名称”,然后转到复选框。

我的XPATH是:

//table[@id="data_configuration_variables_ct_fields_body"]/tbody/tr//td/div/span[@title="CRM" and contains(text(), "CRM")]


我想在XPATH中包含文本“名称”,然后包含复选框。
然后,我可以选择正确的行。

HTML示例是(很长的HTML,很抱歉-我不知道如何以更短的方式提供它):

    <table id="data_configuration_variables_ct_fields_body" cellspacing="0" style="table-layout: fixed; width: 100%;">
<colgroup>
<tbody>
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="0">
<td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
<div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;" tabindex="0">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
<span class="linkhover" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Name</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
<span class="" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Name</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1133" 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>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
<span title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
</tr>
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="1">
<td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBHG">
<div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
<span class="linkhover" title="Address" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Address</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
<span class="" title="Address" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Address</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1133" 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>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
<span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBBH">
</tr>
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="2">
<td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
<div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
<span class="linkhover" title="DOB" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">DOB</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
<span class="" title="DOB" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">DOB</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1133" 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>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
<span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
</tr>
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="3">
<td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBHG">
<div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
<span class="linkhover" title="Phone" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Phone</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
<span class="" title="Phone" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Phone</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1133" 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>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
<span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBBH">
</tr>
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="4">
<td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
<div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
<span class="linkhover" title="Email" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Email</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
<span title="Email" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Email</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1133" 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>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
<span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
<div __gwt_cell="cell-gwt-uid-1135" style="outline-style:none;">
<span class="" title="DM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">DM</span>
</div>
</td>
</tr>
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="5">
<td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBHG">
<div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
<span class="linkhover" title="ACVSEQ" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">ACVSEQ</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
<span class="" title="ACVSEQ" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">ACVSEQ</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1133" 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>
<td class="GJPPK2LBEG GJPPK2LBFH">
<div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
<span class="" title="CRM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">CRM</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBFH GJPPK2LBBH">
<div __gwt_cell="cell-gwt-uid-1135" style="outline-style:none;">
<span class="" title="DM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">DM</span>
</div>
</td>
</tr>
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="6">
<td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBHG">
<div __gwt_cell="cell-gwt-uid-1130" style="outline-style:none;">
<input type="checkbox" tabindex="-1"/>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1131" style="outline-style:none;">
<span class="linkhover" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;color:#00A;cursor:pointer;">Name</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1132" style="outline-style:none;">
<span class="" title="Name" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">Name</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1133" 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>
<td class="GJPPK2LBEG GJPPK2LBGG">
<div __gwt_cell="cell-gwt-uid-1134" style="outline-style:none;">
<span class="" title="ESCR" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">ESCR</span>
</div>
</td>
<td class="GJPPK2LBEG GJPPK2LBGG GJPPK2LBBH">
<div __gwt_cell="cell-gwt-uid-1135" style="outline-style:none;">
<span class="" title="DM" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">DM</span>
</div>
</td>
</tr>
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="7">
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="8">
<tr class="GJPPK2LBEH" __gwt_subrow="0" __gwt_row="9">
<tr class="GJPPK2LBFG" __gwt_subrow="0" __gwt_row="10">

</tbody>
</table>


谢谢,
里亚兹

最佳答案

不要使事情过于复杂(为了可读性而分成多行):

//table[@id="data_configuration_variables_ct_fields_body"]
//tr[td[2]//span = "Name" and td[5]//span = "CRM"]
/td[1]/div/input


在这里,我们找到第二个单元格中带有文本 trspan和第五个文本中带有 NamespanCRM元素。获取适当的行后,我们找到 input元素。

无需像@BenChand所建议的那样上下移动树。

关于python-2.7 - Selenium Python XPATH具有行和列的表如何从col1中选择名称为col2和col5的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35608580/

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