How to find out if a checkbox is checked in Selenium

You can’t reliably use the checked attribute for this, as this only indicates whether that attribute has been set in code (HTML or JavaScript), not whether the user has checked the checkbox. Instead, you need to use the isSelected() method.


boolean isChecked = driver.findElement("myInput")).isSelected();


is_checked = driver.find_element_by_id("myInput").is_selected()


bool isChecked = driver.FindElement(By.Id("myInput")).Selected;