Home > Back-end >  Can't Click Radio Button in Selenium Using Python
Can't Click Radio Button in Selenium Using Python

Time:10-18

Here is the HTML Code:

<div >
    <input type="radio" name="group2" value="yes">
</div>

Full script

Here are the code which i've tried to click the radio button:

driver.find_element(By.CSS_SELECTOR, 'input[name= "group2"][value="yes"]').click()

AND

rdbutton = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[name= "group2"][value="yes"]'))).click()

AND

rdbutton = driver.find_elements(By.XPATH, "//input[@name='group2']")
for rdbuttons in rdbutton:
    if rdbuttons.is_selected():
        pass
    else:
        rdbuttons.click()

CodePudding user response:

It seems that you are using wrong locator. From the HTML you have given i think you are trying to click on radio button that have label Ya if this is the case then try with below xpath:

"//label[contains(text(),'Ya')]"

OR

"//*[normalize-space()='Ya']"

If this does not solve your problem, so please explain and add HTML of proper element either by screenshot or in textual format

  • Related