没有找到这样的元素

No Such Element is found

我正在尝试使用 Selenium 访问下一页上的数据。由于某种原因,我无法在网页上点击提交:https://www.clarkcountycourts.us/Portal/Home/Dashboard/29

我的代码如下:

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()

我收到错误

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

对于最后一行代码,如果能提供任何帮助,我们将不胜感激。

按钮元素如下:

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

在您的代码中,您正在切换到 iframe 并访问其中的一个元素。
但是提交按钮不在该 iframe 中,因此要继续使用该 iframe 之外的元素,您必须切换到默认内容。
这应该会更好:

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()