Related Articles

Related Articles

Working with Radio buttons and Check boxes in Selenium with Python
  • Last Updated : 01 Oct, 2020

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 prpgram.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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 raido 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()

chevron_right


Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :