1

I tried this code to select a radio button:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.asiamiles.com/en/enrolment.html')

gender = driver.find_element_by_id("gender_Female")
gender.click()

I received this error

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

Where could the problem be, and how can I solve it?

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

3 Answers3

1

To click() on the radio button for female you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get("https://www.asiamiles.com/en/enrolment.html")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"label[for='gender_Female']"))).click()
    
  • Using XPATH:

    driver.get("https://www.asiamiles.com/en/enrolment.html")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[@for='gender_Female']"))).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:

female

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

Reason for getting ElementNotInteractableException is that the radio button coordinates are x=0 and y=0, so selenium is not able to click.

enter image description here

Please use this below approach.

imports needed:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Script:

url = 'https://www.asiamiles.com/en/enrolment.html'
driver.get(url)
female = WebDriverWait(driver,30).until(EC.presence_of_element_located((By.CSS_SELECTOR,'.radio-label.bodytext4.F')))
female.location_once_scrolled_into_view
female.click()
supputuri
  • 13,644
  • 2
  • 21
  • 39
0

only using id it wont work when you hover on label tag it shows shaded region of the radio button that's where you need to click. for addition to that it takes a while to load a page so for smooth action use action class and it will click on element.

actions = ActionChains(driver)

gender = driver.find_element_by_xpath(".//input[@name='gender']/following-sibling::label[@for='gender_Female']") 
actions.move_to_element(gender).perform()
Dev
  • 2,739
  • 2
  • 21
  • 34