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:

  • 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

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.