Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix selenium "Message: no such element: Unable to locate element

I need to fix my script I’m still geting the error:

no such element found

Part of my code is:

driver = webdriver.Chrome(r'C:\\chromedriver_win32\\chromedriver.exe')
driver.get("http://bulksmsplans.com/register")
# find username/email field and send the username itself to the input field
country_input = driver.find_element(By.NAME, "country_id")
select_object = Select(country_input)
select_object.select_by_value(country_id)
# find password input field and insert password as well
name_input = driver.find_element(By.NAME, "name")
time.sleep(2)
name_input.send_keys(name)
email_input = driver.find_element(By.NAME, "email")
time.sleep(2)
email_input.send_keys(email)
phone_input = driver.find_element(By.NAME, "phone")
phone_input.send_keys(phone)
time.sleep(2) 
WebDriverWait(driver, 20).until(
    EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[title='reCAPTCHA']")))
WebDriverWait(driver, 20).until(
    EC.element_to_be_clickable((By.CSS_SELECTOR, "div.recaptcha-checkbox-border"))).click()  
button = driver.find_element(By.XPATH, "//input[@type='submit']")
button.click();

All working, but the last step when the bot must to click on green button "Create Account", nope…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is wrong on this line:

button = driver.find_element(By.XPATH, "//input[@type='submit']")

Thanks

>Solution :

While interacting with the reCAPTCHA you have switched to the <iframe>.

Next, to click on the element Create Account you have to shift Selenium‘s focus back to the default content (or parent_frame) using either of the following lines of code:

  • Using default_content():

    driver.switch_to.default_content()
    
  • Using parent_frame():

    driver.switch_to.parent_frame()
    
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading