Click action on Radio button | Selenium Python Forum
G
Gaurav Valera Posted on 04/01/2021

Hi,

Please let me know that following is the best practice to perform click action on radio button?

import time
from selenium import webdriver
from selenium.webdriver.support.select import Select

driver = webdriver.Chrome('C:\\Git_Data\\automationFrameworks\\chromedriver.exe')
driver.maximize_window()
driver.get("https://www.linkedin.com/jobs/jobs-in-sydney-ns?trk=homepage-basic_intent-module-jobs&position=1&pageNum=0")
driver.implicitly_wait(10)

radioButtons = driver.find_elements_by_name('sortBy')
print('Total nos of radio buttons: '+str(len(radioButtons)))

for i in range(1, len(radioButtons)):
    check = radioButtons[i].get_attribute('checked')
    print(check)

# Click 'Most relevant' button
driver.find_element_by_css_selector('body > header > section > form > ul > li:nth-child(1) > div > button').click()
# Select radio button
driver.find_element_by_css_selector('#-dropdown > fieldset > div.filter-list > ul > li:nth-child(2) > label').click()

time.sleep(5)
driver.quit()

J
Jaspreet Replied on 06/01/2021

Hey, 

The method shown is the way you can click a radio button. It is a good way to handle radio buttons


G
Gaurav Valera Replied on 07/01/2021

Thanks please close the ticket


Related Posts