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 program.
Python3
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
driver.find_element_by_xpath(
'//*[@id="q26"]/table/tbody/tr[1]/td/label' ).click()
driver.find_element_by_xpath(
'//*[@id="q15"]/table/tbody/tr[1]/td/label' ).click()
driver.find_element_by_xpath(
'//*[@id="q15"]/table/tbody/tr[2]/td/label' ).click()
|
Output:
Last Updated :
17 Oct, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...