Automate radio button and checkbox in selenium

Hello Guys, Welcome to QA Earth's Selenium tutorial in this post we will see how to automate radio button and checkbox in selenium

Before moving to radio button and checkbox, you should be familiar with HTML as well.

Before moving to Checkbox please refer Basic Selenium Tutorial

HTML For Checkbox
<input type=”checkbox”>
For Radio Button
<input type=”radio”> 



Automate radio button and checkbox in selenium

When you inspect these elements via firebug and firepath you will get above html type.

The main difference between radio button and checkbox is checkbox you can select multiple but for radio button, only one selection is possible.

In Selenium we have 1 method called click() to perform click events.

This click() method you can apply with radio button, checkbox, links and sometime with dropdown as well.
WebElement ele=driver.findElement(By.id()).click();
In this example I have used id only but if you want to make you script stable then you should use Xpath and CSS in your script.

Before performing click action, sometimes we need to verify some activity as well, take some example
  • You need to verify whether radio button or checkbox is enabled.
  • You need to verify whether radio button or checkbox is Displayed on UI or not.
  • You need to verify whether checkbox and radio button is default selected or not.
Above validations are must used in script because automation is all about validation only.

These words looks quite big while listening but we can easily verify this using some predefined method in Selenium.

These methods are


If you notice above scenario before click Selected status was false but after click status changed to TRUE.

Check below image for output.


Once you get the status you can easily verify using Assert in TestNG.

Above example will work for Checkbox as well. Please try from your side and let me know if you help required.