gpt4 book ai didi

Python Selenium 检查复选框输入中的全选

转载 作者:行者123 更新时间:2023-12-01 03:21:48 25 4
gpt4 key购买 nike

我想从输入下拉菜单中选中(全选) 复选框。我怎么能这么做呢?这是下拉菜单的屏幕截图。下拉图标旁边的字段 ID 为 rvrMain_ctl00_ctl09_ctl00

enter image description here

到目前为止,这是我的代码,但没有给我带来好的结果。

checkboxes = browser.find_elements_by_xpath("//input[@id='rvrMain_ctl00_ctl09_ctl00']")
for checkbox in checkboxes:
if not checkbox.is_selected():
checkbox.click()

再次尝试,但仍然没有好的结果。

browser.find_element_by_xpath("//input[@id='rvrMain_ctl00_ctl09_ctl00']").click()

任何帮助将不胜感激。谢谢并致以问候,

阿诺德

编辑

如果我尝试检查字段的元素,这里是 HMTL 代码:

<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td nowrap="nowrap"><span style="font-family:Verdana;font-size:8pt;"><input id="rvrMain_ctl00_ctl09_ctl03_ctl00" name="rvrMain$ctl00$ctl09$ctl03$ctl00" onclick="MVClassrvrMain_ctl00_ctl09.SetAutoPostBackOnHide();MultiValidValuesSelectAll(this, 'rvrMain_ctl00_ctl09_ctl03');" type="checkbox"><label for="rvrMain_ctl00_ctl09_ctl03_ctl00">(Select All)</label></span></td>
</tr>
<tr>
<td nowrap="nowrap"><span style="font-family:Verdana;font-size:8pt;"><input id="rvrMain_ctl00_ctl09_ctl03_ctl01" name="rvrMain$ctl00$ctl09$ctl03$ctl01" onclick="MVClassrvrMain_ctl00_ctl09.SetAutoPostBackOnHide();OnClickMultiValidValue(this, document.getElementById('rvrMain_ctl00_ctl09_ctl03_ctl00'));" type="checkbox"><label for="rvrMain_ctl00_ctl09_ctl03_ctl01">148950&nbsp;-&nbsp;PT.&nbsp;CATUR&nbsp;SENTOSA&nbsp;ADIPRANA&nbsp;-&nbsp;KOTABUMI</label></span></td>
</tr>
<tr>
<td nowrap="nowrap"><span style="font-family:Verdana;font-size:8pt;"><input id="rvrMain_ctl00_ctl09_ctl03_ctl02" name="rvrMain$ctl00$ctl09$ctl03$ctl02" onclick="MVClassrvrMain_ctl00_ctl09.SetAutoPostBackOnHide();OnClickMultiValidValue(this, document.getElementById('rvrMain_ctl00_ctl09_ctl03_ctl00'));" type="checkbox"><label for="rvrMain_ctl00_ctl09_ctl03_ctl02">148961&nbsp;-&nbsp;PT.&nbsp;CATUR&nbsp;SENTOSA&nbsp;ADIPRANA&nbsp;-&nbsp;BANDAR&nbsp;LAMPUNG</label></span></td>
</tr>
--- the list keeps go on and on---
<tr>
<td nowrap="nowrap"><span style="font-family:Verdana;font-size:8pt;"><input id="rvrMain_ctl00_ctl09_ctl03_ctl203" name="rvrMain$ctl00$ctl09$ctl03$ctl203" onclick="MVClassrvrMain_ctl00_ctl09.SetAutoPostBackOnHide();OnClickMultiValidValue(this, document.getElementById('rvrMain_ctl00_ctl09_ctl03_ctl00'));" type="checkbox"><label for="rvrMain_ctl00_ctl09_ctl03_ctl203">320864&nbsp;-&nbsp;PT.&nbsp;LIQUID&nbsp;KENCANA&nbsp;ABADI&nbsp;-&nbsp;NIAS</label></span></td>
</tr>
</tbody>
</table>

我想选择带有标签(全选)的复选框。

编辑

按照 Dilanm 的建议,我修改了代码并且它起作用了。基本上我必须先单击下拉菜单图标,然后单击其中一个复选框。所以这是代码:

browser.find_element_by_id('rvrMain_ctl00_ctl09_ctl01').click() # this one click on the dropdown menu icon
browser.find_element_by_id('rvrMain_ctl00_ctl09_ctl03_ctl00').click() # this one click on the checkbox, either uncheck or check

最佳答案

在您的情况下,您错过了单击元素的向下箭头图标的步骤,因此只需单击向下箭头,下拉项就会可见,然后必须执行您的检查选项。

喜欢 -

browser.find_element_by_xpath(down_arrow_icon_xpath).click()
checkbox = browser.find_element_by_id("rvrMain_ctl00_ctl09_ctl03_ctl00")
if not checkbox.is_selected():
checkbox.click()

关于Python Selenium 检查复选框输入中的全选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41847043/

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