Handling checkboxes in Selenium

Handling checkboxes in Selenium

Checkboxes usually have some identifier to tell if they are checked or not. When working with the default HTML checkboxes, they are an input of type "checkbox" and will have an extra attribute "checked" if they have been checked.

Using this knowledge you can create something that resembles the following XPath for checked boxes:

//input[@type='checkbox' and @checked]

Or for unchecked boxes:

//input[@type='checkbox' and not(@checked)]

Often checkboxes will be more complicated using things like class names to separate checkboxes, but in most of these cases you will still be working with an input and some identifying attribute for whether it is checked or not. In nearly every case, XPath will allow you to identify the desired boxes.

Leave a reply

Your email address will not be published. Required fields are marked*

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.