Here we are going to perform our action on the radio buttons using its value.
Steps to perform the action.
1. find the list of radio buttons using any locator type. This will return a list object.
radio_list = driver.find_elements(By.NAME,"radio")
2. Now Using for loop, iterate the list object (radio_list) and click on the required option (Radio Button2) using its value.
3. Using is_selected() method checks whether the radio button is selected or not.
4. Wait for 5 sec and Close the Web Browser
RadioButtons_by_Value.py
from selenium import webdriver import time from selenium.webdriver.common.by import By driver = webdriver.Chrome("/Users/admin/Documents/Skill2Lead/Others/drivers/chromedriver.exe") driver.get("http://www.dummypoint.com/seleniumtemplate.html") time.sleep(2) # 1. find the list of radio buttons using locator radio_list = driver.find_elements(By.NAME,"radio") time.sleep(2) # 2. Using for loop iterate the list object and click on required option for rbutton in radio_list: rbutton_t = rbutton.get_attribute("value") print(rbutton_t) if rbutton_t == "Button2": rbutton.click() print("Is Selected : ",rbutton.is_selected()) break time.sleep(5) driver.quit()