-1

I have tried to select radio button in selenium python using by_id, by_name but getting error message as:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".radio_1"}
  (Session info: chrome=76.0.3809.100)

I have tried element_by_id(), element_by_name()

import selenium
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://iiiindia.org.in/app#/auth')
aa= driver.find_element_by_id('radio_1').click()

enter code here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Roger
  • 3
  • 1

2 Answers2

1

Before clicking the radio button, you need to wait for it to be ready (clickable):

wait.until(expected_conditions.element_to_be_clickable((By.ID, "radio_1")).click()
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
0

The desired element is an Angular element so to click() on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "md-radio-button#radio_1"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//md-radio-button[@id='radio_1']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

iiiindia

You can find a detailed discussion in Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352