Open In App

Working with Radio buttons and Check boxes in Selenium with Python

Last Updated : 17 Oct, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

  • Take any URL.
  • Select radio button.

  • Navigate radio button using xpath.

  • Select check boxes.
  • Navigate check box using xpath.

  • Use the copied xpaths in the below program.
Python3
# 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
driver.get("https://fs2.formsite.com/meherpavan/form2/index.html?1537702596407")


# 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:


Next Article
Article Tags :
Practice Tags :

Similar Reads