Using Selenium in Python to click/select a radio button

find_elements_by_css_selector worked for me,

browser.find_elements_by_css_selector("input[type='radio'][value='SRF']")[0].click()

Use CSS Selector or XPath to select by value attribute directly, then click it.

browser.find_element_by_css_selector("input[type='radio'][value='SRF']").click()
# browser.find_element_by_xpath(".//input[@type='radio' and @value='SRF']").click()

Corrections (but OP should learn how to look up in documentation)

  • In Python binding, find_elements_by_css doesn't exist, it's called find_elements_by_css_selector. One should be able to look at the exception message and look back into documentation here and figure out why.
  • Notice the difference between find_element_by_css_selector and find_elements_by_css_selector? The first one finds the first matching element, the second one finds a list, so you need to use [0] to index. Here is the API documentation. The reason why I use the latter, is because I copied your code, which I shouldn't.

Enter image description here

Selenium webdriver Radio button click

When i used xpath :

driver.find_element_by_xpath("//input[@id='id_gender2']").click()

radio button not selected

But I used css_selector :

driver.find_element_by_css_selector("input#id_gender1").click() 

radio button selected