没有这样的元素异常。无法在 selenium python 中定位元素

No such element exception. Unable to locate element in selenium python

我想抓取来自 https://www.archionweb.be/ on this page https://www.archionweb.be/Public/Company/1930 的电子邮件。

电子邮件在验证码中受到保护,所以我的想法是点击验证码然后提取电子邮件。但是每当我试图点击验证码按钮(我同时使用了 XPath 和 CSS 选择器)时,就会出现异常:

"no such element: Unable to locate element"

如果有人能帮我解决这个问题。

由于我们在点击 I am not a Robot 后仍处于自动化状态,因此有时会再次提供验证码。能够点击带有以下代码的复选框。

from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains


driver = webdriver.Chrome(executable_path="path to chromedriver.exe")
driver.maximize_window()
driver.implicitly_wait(30)
driver.get("https://www.archionweb.be/Public/Company/1930")
time.sleep(5)
iframe = driver.find_element_by_xpath("//iframe[@title='reCAPTCHA']")
driver.switch_to.frame(iframe)
time.sleep(5)
recaptcha = driver.find_element_by_class_name("recaptcha-checkbox-borderAnimation")
driver.execute_script("arguments[0].scrollIntoView(true);",recaptcha)
ActionChains(driver).move_to_element(recaptcha).click().perform()
time.sleep(2)
driver.switch_to.default_content()