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...
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...
Its easy. Just do something like this:
List<WebElement els = driver.findElements( By.class( "input") );
for ( WebElement el : els ) {
if ( !el.isSelected() ) {
el.click();
}
}
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();
}
}
@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();
}
}
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();
}
Check the multiple check boxes using Selenium in python:
checkboxes=browser.find_elements_by_xpath('//input[@type="checkbox"]')
for checkbox in checkboxes:
checkbox.click()