简体   繁体   中英

Python Selenium check select all in checkbox input

I want to check the (SELECT ALL) checkbox from the input dropdown menu. How could I do that? Here is the screenshot of the dropdown menu. The field's id next to the dropdown icon is rvrMain_ctl00_ctl09_ctl00 .

在此处输入图片说明

So far here is my code, but gave me no good result.

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

Another try, but still no good result.

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

Any help will be much appreciated. Thanks and regards,

Arnold

EDIT

If I try to inspect the element of the field, here is the HMTL code:

<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>

I want to select the checkbox with label (Select All) .

EDIT

As suggested by Dillanm, I revised my code and it worked. Basically I have to click on the dropdown menu icon first, and then click on the one of the checkboxes. So here is the code:

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

In your case you are missing the step to click on the down arrow icon of your element So Just click the down arrows, the dropdown items get visible and then have to perform your check option.

Like -

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM