python-3.x - 消息:没有这样的元素:无法找到元素:{"method":"css selector","selector":".recaptcha-checkbox-border"}
问题描述
我正在尝试使用 Selenium 绕过验证码验证,但我不断收到此错误
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".recaptcha-checkbox-border"}
我已经尝试过使用sleep(20)
,但它不起作用。这是我试图绕过验证码的链接:https ://whitepages.co.nz/ycaptcha?next=%2Fwhite-all%2Fhalswell%2Fchristchurch%2F
如果我在选择器类中犯了错误,请告诉我。
解决方案
reCAPTCHA在 an 内,因此<iframe>
您必须:
诱导WebDriverWait使所需的帧可用并切换到它。
诱导WebDriverWait使所需元素成为可点击的。
您可以使用以下任一定位器策略:
使用
CSS_SELECTOR
:driver.get("https://whitepages.co.nz/ycaptcha?next=%2Fwhite-all%2Fhalswell%2Fchristchurch%2F") WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.google.com/recaptcha/api2/anchor']"))) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.recaptcha-checkbox-border"))).click()
使用
XPATH
:driver.get("https://whitepages.co.nz/ycaptcha?next=%2Fwhite-all%2Fhalswell%2Fchristchurch%2F") WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[starts-with(@src, 'https://www.google.com/recaptcha/api2/anchor')]"))) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='recaptcha-checkbox-border']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
浏览器快照:
参考
您可以在以下位置找到一些相关的讨论:
推荐阅读
- java - 显示表单@postMapping EL1007E:在 null 上找不到属性或字段“名称”
- c++ - 使用模板在代码中可视化 2D 和 3D 形状
- swift - 如何将位于 UI View 中的长文本标签制作成 Swift 中的多行?
- reactjs - 使用带有样式组件和主题的 react-test-renderer (React Native)
- game-physics - 如何让两个非物理角色在虚幻引擎 4 中正确交互,导致一个“反弹”?
- flutter - 如何将小部件移动到特定位置?
- azure - DPM 备份存储在 Azure 中的什么位置?
- webpack - Webpack@5 中 `MainTemplate.hooks.beforeStartup` 的替代方案
- qt - Qml如何恢复绑定?
- jboss - JBoss 服务失败