Open In App

Working with Radio buttons and Check boxes in Selenium with Python

Prerequisite: Browser Automation Using Selenium

Requirement: You need to install chrome driver and set path. Click here to download. 



Selenium is an effective device for controlling an internet browser through the program. It is purposeful for all browsers, works on all fundamental OS and its scripts are written in numerous languages i.e Python, Java, C#, etc, we can be running with Python.

Approach:






# Import selenium module
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
 
 
# Using chrome driver
driver = webdriver.Chrome()
 
 
# Web page url
 
 
# Selecting radio button
# Select male
driver.find_element_by_xpath(
    '//*[@id="q26"]/table/tbody/tr[1]/td/label').click()
 
 
# Selecting check box
# Select sunday
driver.find_element_by_xpath(
    '//*[@id="q15"]/table/tbody/tr[1]/td/label').click()
 
 
# Select monday
driver.find_element_by_xpath(
    '//*[@id="q15"]/table/tbody/tr[2]/td/label').click()

Output:

Article Tags :