Using Selenium in Python to click/select a radio button.


We can select/click the radio button with Selenium. In an html document, each radio button has an attribute type set to a value as radio. In order to select a radio button, we shall first identify it and then apply the click() method to it.

Example

Code Implementation.

from selenium import webdriver
driver = webdriver.Chrome (executable_path="C:\chromedriver.exe")
# maximize with maximize_window()
driver.maximize_window()
driver.get("https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm")
# identify element and click()
l=driver.find_element_by_xpath("//input[@value='2']")
l.click()
driver.close()

Output

Updated on: 28-Aug-2020

899 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements