Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

self.browser.find_element_by_xpath("//input[@name='arr[]']").click()

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

share|improve this question
    
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. –  vincebowdren Aug 6 '13 at 8:54

4 Answers 4

Try changing your Xpath to:

//input[@name='arr[]'][2]
share|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++) {
  lc.get(i).click();
}
share|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
checkboxes = self.browser.find_elements_by_xpath("//input[@name='arr[]']")
for checkbox in checkboxes:
    if not checkbox.isSelected():
        checkbox.click()

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

    self.browser.find_elements_by_xpath("//input[@name='arr[]']")
    Note that it is find_elements_by_xpath (plural)

  2. Loop through the list to check all checkbox

share|improve this answer

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

<tr>
<td>check</td>
<td>loggerCheck</td>
<td></td>

<tr>
    <td>uncheck</td>
    <td>loggerCheck</td>
    <td></td>
</tr>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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