1

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.

enter image description here

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
arnold
  • 598
  • 2
  • 11
  • 24
  • Can you share `HTML` of pop-up? – Andersson Jan 25 '17 at 08:53
  • have you performing click on the down arrow button of dropdown before moving to checkbox ? – NarendraR Jan 25 '17 at 08:54
  • You could try the Select class from the WebDriver Support package; see [this](http://stackoverflow.com/a/28613320/3110529) answer for more details (not sure if it will work with checkboxes though) – Dillanm Jan 25 '17 at 09:33
  • @NarendraRajput No I have not. I will try your suggestion, by clicking the dropdown icon first then move to the checkbox. Thanks for the suggestion! – arnold Jan 25 '17 at 09:40
  • @Dillanm Thanks for the link. I will also give it a try. Will come back to you guys soon. – arnold Jan 25 '17 at 09:41
  • 1
    @Dillanm thanks mate! Yes you are right. I have to click on the icon first and followed by click the checkbox. Now I can check the `(Select All)` checkbox! How can I mark that your comment is the right answer? – arnold Jan 25 '17 at 10:00
  • @arnold Are you sure this solved the issue, could you show us the code which fixed it? – Dillanm Jan 25 '17 at 12:13
  • 1
    @Dillanm sorry for my tardy reply. Please see the updated post. I added my final code. – arnold Jan 31 '17 at 15:16

1 Answers1

2

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()
NarendraR
  • 7,577
  • 10
  • 44
  • 82
  • First line will cause error as you're trying to click on list (use `find_element` instead of `find_elements`). Also second line will return `0` elements as there is no `input` fields with `id='rvrMain_ctl00_ctl09_ctl00'` in provided `HTML` code (but this seem to be OP misleading). As target check-box is initially known there is no need to loop through all the options, you can just use `"(Select All)"` to check exact – Andersson Jan 25 '17 at 10:37
  • @Andersson, you are right , The problem was he missed to click on down arrow icon . So i did mentioned that and pasted the code in hurry . Thanks for remind :) – NarendraR Jan 25 '17 at 10:48