I\'m using Selenium 2 (Webdriver) for automating tests on a webpage. However I wonder if there is way to check checkbox from the list of checkboxes using webdriver framework
Java, Clicking on multiple checkboxes at a time using the loop.
**Sample Xpath :**
CheckBox1 Xpath : //input[@class='mycheck' and @id='1']
CheckBox2 Xpath : //input[@class='mycheck' and @id='2']
Get all the elements checkbox using findelements:
List WebElement ele = driver.findElements(By.xpath("//input[@class='mycheck']"));
Make the Xpath as string by leaving the ID and assign the ID as i.
for(int i=1; i<=ele.size(); i++) { driver.findElement(By.xpath("//input[@class='mycheck' and @id='" + + i + "']")).click(); }
i gets the value for every loop and the xpath matches the checkbox and click's it.