TestProject Forum
Powered by leading experts in the test automation community

Check multiple checkboxes with Selenium

I have the following HTML:

<input class="ai-color" type="checkbox" value="Orange"><br>
<input class="ai-color" type="checkbox" value="Green"><br>
<input class="ai-color" type="checkbox" value="Purple"><br>

I would like to check all the checkboxes simultaneously not just 1
How can i do it in selenium ?

You could use the findElements method and iterate over them with a loop and click them all:

List<WebElement> inputs = driver.findElements(By.className("ai-color"));
for (WebElement input : inputs) {
    input.click();
}