HTML code:

<div class="form-group">
    <label for="exampleInputEmail1">Gender</label>
    <input id="optionsRadios1" type="radio" value="Male" checked="" name="gender"/>
    <input id="optionsRadios1" type="radio" value="Female" name="gender"/>

How do I select and click on the radio button if it's already Checked?

  • Welcome to SQA! In the future please include actual code rather than a screenshot--this will make it easier for others to read and help you. Also, it looks like both of your radio buttons have the same ID, which is bound to cause problems.
    – c32hedge
    May 23, 2017 at 16:45

3 Answers 3


First you need to check whether the radio button is selected or not.

Second if the radio button is already selected don't do anything but if the radio button is not selected then you need to click on the radio button.

You can do this using the below code.

//Getting the radio button webelement.
WebElement radio_Button = driver.findElement(By.id("xyz");

//Checking if the radio is selected or not
  radio_Button.click();//If the radio button is not selected click on the radion button

There is already an answer here:


Try checking if button is selected, then clicking

if (driver.findElement(By.Id(' ')).isSelected() == false)
       driver.findElement(By.Id(' ')).Click()
  • 3
    .isSelected() method returns a Boolean. So no need to compare it with false
    – Alok
    May 22, 2017 at 12:16

Here is the answer in Python, in case you're not using Java.

radio_button = driver.find_element_by_id("<id>")

if radio_button.is_selected():

More information can be found here: https://stackoverflow.com/questions/14442636/how-can-i-check-if-a-checkbox-is-checked-in-selenium-python-webdriver

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.