How to Select and Verify Radio Buttons in Selenium: Examples and Best Practices

Step-by-step guide to selecting and verifying radio buttons in Selenium. Includes practical examples and expert tips for better automation.

Written by Grandel Robert Grandel Robert
Reviewed by Ashwani Pathak Ashwani Pathak
Last updated: 29 July 2026 12 min read

Key Takeaways

  • In Selenium WebDriver, handling radio buttons involves finding the specific HTML element and interacting with it using built-in methods.
  • Stable locators and explicit waits make radio button tests more reliable. Rely on consistent attributes instead of dynamic IDs, and wait for elements to become interactable before clicking them.
  • Run your tests on real browsers and devices to validate actual user behaviour. A test that passes locally should also work consistently across different browsers, operating systems, and mobile devices.

Selenium is one of the most reliable tools for automating web interactions. One element I work with regularly is the radio button. It’s commonly used in forms where users need to choose a single option from a group, such as selecting a payment method or subscription plan.

Automating these interactions helps verify that the correct option can be selected, the application responds as expected, and the user experience remains consistent across browsers. We’ll cover more on this concept through this article.

How does Selenium Interact with Radio Buttons?

Radio buttons are one of the simplest form elements you’ll automate with Selenium. They let users choose a single option from a group, making them common in forms for things like payment methods, delivery options, or account preferences.

From a testing perspective, interacting with a radio button is straightforward. I usually locate the element using Selenium locators such as ID, name, CSS Selector, or XPath, then verify that the correct option is selected before continuing with the rest of the test.

Typical Form Interactions

You’ll come across radio buttons in almost every application that asks users to make a single choice. Since only one option can be selected at a time, they’re commonly used in forms and checkout flows where the application needs a clear decision before moving forward.

  • User preferences: Choosing options such as a subscription plan, notification preference, or account type.
  • Payment methods: Selecting how a purchase should be completed before proceeding to checkout.
  • Surveys and feedback: Recording a single response for ratings, satisfaction levels, or opinion-based questions.
  • Shipping options: Letting users choose one delivery method based on speed or cost.

Read More: How to handle Checkbox in Selenium

I usually include these interactions in my automation suite because they’re often part of critical user journeys. Verifying that the correct option can be selected and retained helps ensure forms behave as users expect.

How to Select a Radio Button

Once you’ve located a radio button, selecting it is simply a matter of calling Selenium’s click() method. The main difference is how you identify the element. Whenever possible, I start with the most stable locator and only move to more flexible options when necessary

1. By ID

If the radio button has a unique id, this is usually my first choice. IDs are fast to locate and tend to be more stable than complex selectors.

from selenium import webdriver

from selenium.webdriver.common.by import By



driver = webdriver.Chrome()



driver.get("https://example.com/radio-button")



button = driver.find_element(By.ID, "yesRadio")

button.click()



driver.quit()

2. By Name

Radio buttons that belong to the same group often share the same name attribute. This works well when you know the group you’re interacting with.

button = driver.find_element(By.NAME, "like")

button.click()

3. By XPath

I usually fall back to XPath when there isn’t a reliable ID or name available. It’s flexible enough to target elements using multiple attributes or their position in the DOM.

button = driver.find_element(

    By.XPATH,

    "//input[@id='yesRadio']"

)



button.click()

4. By CSS Selector

CSS Selectors are another reliable option and are often easier to read than long XPath expressions. They’re a good choice when you’re selecting elements based on IDs, classes, or other attributes.

button = driver.find_element(

    By.CSS_SELECTOR,

    "#yesRadio"

)



button.click()

Tip: I always prefer ID → Name → CSS Selector → XPath whenever possible. Simpler locators are usually easier to maintain and less likely to break when the application’s HTML changes.

Checking the Selected State

Once a radio button is selected, it’s important to verify whether the correct option was chosen. Selenium provides various techniques to confirm if a radio button is selected, ensuring the accuracy of your automation tests.

Techniques to Confirm if the Correct Radio Button is Selected:

1. Using isSelected() Method

The isSelected() method is the most straightforward way to check if a radio button is selected. This method returns True if the radio button is selected, and False otherwise.

button=driver.find_element(By.ID, 'yesRadio')

if button.is_selected():

   print("Radio button is selected.")

else:

   print("Radio button is not selected.")

2. Validating Selection Through Attribute Values

Another way to verify the selection is by checking the checked attribute of the radio button. When selected, the radio button typically has a checked attribute.

button=driver.find_element(By.ID, 'yesRadio')

if button.get_attribute("checked") == "true":

   print("Radio button is selected.")

else:

   print("Radio button is not selected.")

Working with Dynamic Elements

One challenge you’ll eventually run into is radio buttons whose attributes change every time the page loads. If your locator depends on a generated id, your test is likely to become flaky. In these situations, I look for attributes that remain consistent, such as labels, values, or element relationships.

Locate by Label with XPath

If the associated label text doesn’t change, XPath provides a reliable way to locate the corresponding radio button without depending on a dynamic ID.

button = driver.find_element(

    By.XPATH,

    "//label[text()='Option 1']/preceding-sibling::input[@type='radio']"

)



button.click()

Use Stable Attributes with CSS Selectors

If the element has attributes such as type, value, or a consistent class name, a CSS Selector is often simpler and easier to maintain than XPath.

button = driver.find_element(

    By.CSS_SELECTOR,

    "input[type='radio'][value='option1']"

)



button.click()

I generally avoid targeting randomly generated IDs whenever possible. Locators based on labels, values, or other stable attributes tend to survive UI changes much better, which means fewer broken tests and less maintenance over time.

Troubleshooting Common Issues

Clicking a radio button is usually straightforward, but real applications aren’t always that simple. I’ve run into cases where the element exists but isn’t ready to receive a click, is temporarily disabled, or there are multiple groups on the same page. Here’s how I typically handle each situation.

Wait Until the Element Is Clickable

If Selenium throws an ElementClickInterceptedException or ElementNotInteractableException, the page may not have finished rendering. Instead of adding fixed delays, wait until the element is actually clickable.

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC



button = WebDriverWait(driver, 10).until(

    EC.element_to_be_clickable((By.ID, "yesRadio"))

)


button.click()

Using an explicit wait makes the test more reliable and avoids unnecessary pauses.

Check Whether the Element Is Enabled

Some forms disable options until another action has been completed. Before clicking, it’s worth verifying that the radio button is enabled.

radio_button = driver.find_element(By.ID, "yesRadio")



if radio_button.is_enabled():

    radio_button.click()

else:

    print("Radio button is disabled.")

If the element isn’t enabled, I usually investigate the application flow rather than trying to force the interaction.

Interacting with Hidden Elements

Sometimes the actual radio button is hidden and the visible label handles the click instead. If you need to interact with the hidden input directly, JavaScript can trigger the click.

radio_button = driver.find_element(By.ID, "yesRadio")



driver.execute_script(

    "arguments[0].click();",

    radio_button

)

I only use this approach when there’s no better alternative, since clicking the element the user actually interacts with gives a more realistic test.

Working with Multiple Groups

Pages often contain several sets of radio buttons, such as one group for shipping options and another for payment methods. In these cases, make your locator specific to the group instead of searching the entire page.

payment_group = driver.find_element(By.ID, "payment-options")



credit_card = payment_group.find_element(

    By.XPATH,

    ".//input[@value='credit-card']"

)



credit_card.click()

Scoping your search to the correct container makes your tests easier to read and reduces the chance of selecting the wrong option when multiple groups contain similar values.

Getting More Reliable Results With This Function

When testing radio buttons in Selenium, following best practices ensures the clarity, maintainability, and effectiveness of your tests. Implementing these practices also helps improve the robustness of your automation scripts.

1. Use Descriptive Locators for Clarity and Maintainability

Descriptive locators make your code more readable and easier to maintain. Instead of using generic locators like id or class, try to use meaningful attributes, such as labels or values, that clearly indicate the button’s purpose. This approach improves your ability to update or extend tests without confusion.

For example, use labels or custom attributes for more precise identification:

radio_button = driver.find_element(By.XPATH, "//input[@type='radio' and @value='option1']")

radio_button.click()

2. Automate Validations for All States of Radio Buttons (Selected, Unselected, Disabled)

Automating validations for all possible states of radio buttons is critical. Ensure you verify whether a radio button is selected, unselected, or disabled, depending on the test scenario. This helps ensure your tests cover all interaction possibilities and behaviors.

You can automate the validation of each state using the isSelected() and isEnabled() methods:

# Validate if the radio button is selected

assert radio_button.is_selected() == True

# Validate if the radio button is disabled

assert radio_button.is_enabled() == False

3. Modularize Code for Reusable Radio Button Interaction Functions

Modularizing your code for interactions with radio buttons makes your tests more maintainable and reusable. By creating functions for selecting and verifying radio buttons, you avoid repeating the same code in multiple test cases.

For example, a reusable function for selecting a radio button might look like this:

def select_radio_button(driver, radio_button_id):

   radio_button = driver.find_element(By.Namradio_button_id)

   if not radio_button.is_selected():

       radio_button.click()
     

# Usage

select_radio_button(driver, "radio_option_1")

4. Ensure Cross-Browser Compatibility in Radio Button Tests

Different browsers may handle radio buttons slightly differently. To ensure consistent behavior, you must run your tests across multiple browsers (Chrome, Firefox, Safari, etc.). You can achieve this using Selenium Grid or BrowserStack for cross-browser testing.

Real-World Test Scenarios

Selecting a radio button is only one part of the test. In most applications, you’ll also need to verify that the correct option is selected, previous selections are cleared, and the application responds as expected. Here are a few scenarios I find myself automating regularly.

Verify the Default Selection

Many forms preselect an option. Before interacting with the page, verify that the expected choice is already selected.

default_radio = driver.find_element(By.ID, "default_radio")



assert default_radio.is_selected()

If your test requires a different option, you can switch the selection before continuing.

if not default_radio.is_selected():

    default_radio.click()

Switch Between Options

One of the defining characteristics of radio buttons is that only one option in a group can remain selected. Whenever I automate this interaction, I verify both the newly selected option and the one that should have been deselected.

first = driver.find_element(By.ID, "radio_option_1")

second = driver.find_element(By.ID, "radio_option_2")



first.click()



assert first.is_selected()

assert not second.is_selected()



second.click()



assert second.is_selected()

assert not first.is_selected()

This confirms that the application is enforcing the single-selection rule correctly.

Validate Form Behaviour

Radio button selections often control what happens next. A form might display additional fields, enable the Submit button, or show a validation message based on the user’s choice. Rather than checking the radio button alone, verify the behaviour that follows.

driver.find_element(By.ID, "radio_option_1").click()

driver.find_element(By.ID, "submit_button").click()



success = driver.find_element(By.ID, "success_message")



assert success.is_displayed()

Tests like this provide more value because they confirm the application reacts correctly to the user’s selection, not just that the click was successful.

Why Test on BrowserStack?

Running the same Selenium test on real devices like BrowserStack Automate helps catch inconsistencies before your users do. Let’s look at how this helps:

  • Real device cloud: Make sure radio buttons respond correctly to mouse clicks, touch gestures, and keyboard navigation across desktop and mobile devices.
  • Cross browser testing: Verify that selection, focus states, and form behaviour remain consistent in Chrome, Firefox, Safari, Edge, and other supported browsers.
  • Run tests in parallel: Execute the same test suite across multiple browser and device combinations to reduce execution time.
  • Debug failures faster: Review screenshots, videos, logs, and session details to understand why a radio button behaved differently on a specific browser or device.
  • Integrate into your workflow: Run Selenium tests automatically through your existing CI/CD pipeline so radio button interactions are validated with every build.

Rather than assuming a radio button works everywhere because it passes locally, BrowserStack lets you verify that users have the same experience across the environments they actually use.

Conclusion

Radio buttons are one of the simplest form elements you’ll automate, but they’re also part of many critical user journeys. I’ve found that a reliable test doesn’t stop at clicking an option. It verifies that the correct choice is selected, the previous one is cleared, and the application responds the way a user would expect.

Choosing reliable locators, validating the application’s behaviour after each selection, and running your tests across real browsers and devices gives you much greater confidence that the experience remains consistent for every user.

Version History

  1. Jul 29, 2026 Current Version

    Updated code examples with screenshots and real-world examples and edge case scenarios, and added key takeaways and references.

    Ashwani Pathak
    Reviewed by Ashwani Pathak Automation Expert
Tags
Automation Testing Website Testing
Grandel Robert
Grandel Robert

Senior Automation Expert

Grandel D'Souza is a software quality and test automation professional with 8+ years of experience in quality engineering and software testing. He specializes in building scalable automation solutions and helping teams improve software reliability, release velocity, and testing efficiency.

Automation Tests on Real Devices & Browsers
Seamlessly Run Automation Tests on 3500+ real Devices & Browsers