How can I select checkboxes using the Selenium Java WebDriver?

The Solution to How can I select checkboxes using the Selenium Java WebDriver? is


Selecting a checkbox is similar to clicking a button.

driver.findElement(By.id("idOfTheElement")).click();

will do.

However, you can also see whether the checkbox is already checked. The following snippet checks whether the checkbox is selected or not. If it is not selected, then it selects.

if ( !driver.findElement(By.id("idOfTheElement")).isSelected() )
{
     driver.findElement(By.id("idOfTheElement")).click();
}

~ Answered on 2013-02-04 09:54:53


Most Viewed Questions: