Search code examples
pythonseleniumiframeselenium-chromedriver

No Such Element is found


I'm trying to use Selenium to access data on the next page. For some reason, I can't get it to click submit on the web page: https://www.clarkcountycourts.us/Portal/Home/Dashboard/29

my code is as followed:

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


options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(20) # gives an implicit wait for 20 seconds

driver.get("https://www.clarkcountycourts.us/Portal/Home/Dashboard/29")

search_box = driver.find_element_by_id("caseCriteria_SearchCriteria")
search_box.send_keys("Robinson")

WebDriverWait(driver, 15).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))
WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='recaptcha-anchor']"))).click()

submit_box = driver.find_element_by_id("btnSSSubmit").click()

I get the error

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="btnSSSubmit"]"}

for the last line of code submitting any assistance would be greatly appreciated.

the button elements are as followed:

<input name="Search" id="btnSSSubmit" class="btn btn-primary pull-right" value="Submit" type="submit">

Solution

  • In your code you are switching into the iframe and accessing an element inside it.
    But the submit button is not inside that iframe, so to continue with elements out of that iframe you have to switch to the default content.
    This should work better:

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
    
    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    driver = webdriver.Chrome(options=options)
    driver.implicitly_wait(20) # gives an implicit wait for 20 seconds
    
    driver.get("https://www.clarkcountycourts.us/Portal/Home/Dashboard/29")
    
    search_box = driver.find_element_by_id("caseCriteria_SearchCriteria")
    search_box.send_keys("Robinson")
    
    WebDriverWait(driver, 15).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))
    WebDriverWait(driver, 15).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='recaptcha-anchor']"))).click()
    driver.switch_to.default_content()
    
    submit_box = driver.find_element_by_id("btnSSSubmit").click()