Check multiple checkboxes with Selenium

  • 1 Replies
  • 773 Views
Check multiple checkboxes with Selenium
« on: June 14, 2016, 10:14:38 am »
I have the following HTML:

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

*

Oren

  • **
  • 59
Re: Check multiple checkboxes with Selenium
« Reply #1 on: June 15, 2016, 18:30:16 pm »
You could use the findElements method and iterate over them with a loop and click them all:

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

 

Sitemap 1 2 3 4 5 6 7 8