python-3.xseleniumselenium-webdriverwebdrivernosuchelementexception

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...

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: