Tuesday, 20 March 2018

How to Automate Radio button and Checkbox in Selenium webdriver

In this post we are going to learn about how to test checkboxes and radio buttons using selenium.Before jumping into that
let us see how the html code for checkbox and radio button looks like.
HTML For Checkbox
<input type=”checkbox”>
HTML For Radio Button
<input type=”radio”>

The main difference between radio button and checkbox is checkbox you can select multiple but for radio button, only one selection is possible.
we can perform click action using selenium click() method but before that it is very important to verify / test some conditions listed below-

  •     isEnabled()-You need to verify whether radio button or checkbox is enabled.
  •     isDisplayed()-You need to verify whether radio button or checkbox is Displayed on UI or not.
  •     isSelected()-You need to verify whether checkbox and radio button is default selected or not.
Video Tutorial - 

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class RadioButtonTest {

WebDriver driver;

     public  void test() throws Exception {
 System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\chromedriver_win32\\chromedriver.exe");
    WebDriver driver=new ChromeDriver();


         WebElement female_radio_button=driver.findElement(By.id("u_0_b"));
         boolean status=female_radio_button.isDisplayed();
         System.out.println("Female radio button is Displayed >>"+status);
          boolean enabled_status=female_radio_button.isEnabled();
          System.out.println("Female radio button is Enabled >>"+enabled_status);
        boolean selected_status=female_radio_button.isSelected();
          System.out.println("Female radio button is Selected >>"+selected_status);
        boolean selected_status_new=female_radio_button.isSelected();
          System.out.println("Female radio button is Selected >>"+selected_status_new);


You can practice with same code for chekboxes. Do try and share your feedback, suggestions and questions in the comment section below.


  1. I am happy to find this post Very useful for me, as it contains lot of information

    Selenium Course in Chennai

    Selenium Training Institute in Chennai

    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

  2. Webtrackker is the largest training partner in Salesforce.com .Webtrackker develops and offers sales force training for end users, customer support and marketing, as well as managers, developers and consultants.

    Salesforce training institute in Noida, Salesforce training in Noida