I've got this HTML code

<input type="checkbox" value="abc" name="arr[]><br>
<input type="checkbox" value="abc1" name="arr[]><br>
<input type="checkbox" value="abc2" name="arr[]><br>

With this


I can check only the first checkbox, but I want check all check box in the same time. How I can do it?

  • You probably can't check all the checkboxes at the same time (actually simultaneously). That's an action which would be impossible for a normal user, so selenium is unlikely to provide a way to do so. – Vince Bowdren Aug 6 '13 at 8:54
checkboxes = self.browser.find_elements_by_xpath("//input[@name='arr[]']")
for checkbox in checkboxes:
    if not checkbox.isSelected():

(Previous answer):

I am not yet familiar with the python syntax, but this is what you can do:

  1. Return all elements with the given xpath:

    Note that it is find_elements_by_xpath (plural)

  2. Loop through the list to check all checkbox

| improve this answer | |

Try changing your Xpath to:

| improve this answer | |

In Java that would be:

WebElement box = driver.findElement(By.xpath(".//*[@id='multi-selections']"));
List<WebElement> lc = box.findElements(By.tagName("input"));
for (int i = 0; i <= lc.size(); i++) {
| improve this answer | |
  • Please, add an information you're answer is in Java, while question was about Python – dzieciou Nov 1 '12 at 17:04

In selenium IDE there is a command named check and un check so you can use the command for your testing case if needed.


| improve this answer | |

Find element (singular returns only the first element that matches), whereas find_elements returns an iterable list of all matches. As Suchit explained, you can loop through the list.

You can also select an individual box in the list using the index. For example, to select the second box: driver.find_elements_by_xpath("//input[@name='arr[]']")[1].click()

| improve this answer | |

Suchit Parikh's Answer is close, but when selenium tries to click the second checkbox, it is likely that it will throw a StaleElementReferenceException

You can get by this by storing some unique information from the check boxes in another list, then iterate through that new list and finding the elements again.


   elements = self.driver.find_elements_by_xpath("//input[@name='arr[]']")

   element_list = []
   for elm in elements:

   for elem_value in element_list:
       self.driver.find_element_by_xpath("//input[@value='" + elem_value + "']").click()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.