Python - Selenium - Check radio buttons and checkboxes

By xngo on June 18, 2019

The Python code below shows you how to check radio buttons and checkboxes using different Selenium locators.

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Create chrome driver.
driver = webdriver.Chrome()
# Open the webpage.
# Pause for 5 seconds for you to see the initial state.
# Radio Button: Check Monday using XPATH locator.
element = driver.find_element_by_xpath("//input[@value='Mon']")
# Checkbox: Uncheck Apple using CSS selector.
element = driver.find_element_by_css_selector("input[name='apple']")
# Checkbox: Check Orange using CSS selector.
element = driver.find_element_by_css_selector("input[name='orange']")
# Pause for 10 seconds so that you can see the results.
# Close.

Here is a video showing the code above in action.

Output of Selenium: Check radio button and checkboxes

About the author

Xuan Ngo is the founder of He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.