Reputation: 31
I'm new to selenium web driver and I need to select multiple checkbox to Submit the form and the following code response in HTML format.
Please find the attached screenshot and kindly suggest an idea to select multiple checkbox, random etc...
Upvotes: 0
Views: 36795
Reputation: 140
Check the multiple check boxes using Selenium in python:
checkboxes=browser.find_elements_by_xpath('//input[@type="checkbox"]')
for checkbox in checkboxes:
checkbox.click()
Upvotes: 0
Reputation: 1
List<WebElement>
chk = driver.findElements(By.xpath("//input[@type='checkbox']"));
Iterator<WebElement> itr = chk.iterator();
while (itr.hasNext() ){
if(!itr.next().isSelected())
itr.next().click();
}
Upvotes: 0
Reputation: 3596
@Test(priority=11)
public void Test_CheckBox_Check()throws InterruptedException
{
List<WebElement> els = driver.findElements(By.xpath("//div[@class='md-container md-ink-ripple']"));
System.out.println(Integer.toString(els.size()));
for ( WebElement el : els ) {
el.click();
}
}
Upvotes: 0
Reputation: 2584
A bit modified @djangofan answer (his code selects not only checkbox inputs):
List<WebElement els = driver.findElements(By.xpath("//input[@type='checkbox']"));
for ( WebElement el : els ) {
if ( !el.isSelected() ) {
el.click();
}
}
Upvotes: 1
Reputation: 29669
Its easy. Just do something like this:
List<WebElement els = driver.findElements( By.class( "input") );
for ( WebElement el : els ) {
if ( !el.isSelected() ) {
el.click();
}
}
Upvotes: 1