Python 3.x 消息:没有这样的元素:无法定位元素:{quot;方法";:“css选择器”;“选择器”:“重选复选框边框”}
我正试图使用Selenium绕过验证码验证,但我一直遇到这个错误Python 3.x 消息:没有这样的元素:无法定位元素:{quot;方法";:“css选择器”;“选择器”:“重选复选框边框”},python-3.x,selenium,iframe,recaptcha,webdriverwait,Python 3.x,Selenium,Iframe,Recaptcha,Webdriverwait,我正试图使用Selenium绕过验证码验证,但我一直遇到这个错误 selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".recaptcha-checkbox-border"} 我已经试过使用
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".recaptcha-checkbox-border"}
我已经试过使用sleep(20)
,但它不起作用。以下是我试图绕过验证码的链接:
请让我知道,如果我在选择器类或任何错误
<iframe src="https://www.google.com/recaptcha/api2/anchor?ar=1&k=6LepxvIZAAAAAPGd49tlErQ-2da9Bh-3yN_gCjul&co=aHR0cHM6Ly93aGl0ZXBhZ2VzLmNvLm56OjQ0Mw..&hl=en&v=2Mfykwl2mlvyQZQ3PEgoH710&size=normal&cb=r4uh76mv0o72" width="304" height="78" role="presentation" name="a-taqeeo56s3nk" frameborder="0" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox"></iframe>
进口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
在
中,因此您必须:
- 使所需帧可用并切换到该帧
- 使所需元素可单击
- 您可以使用以下任一选项:
- 使用
:CSS\u选择器
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
- 浏览器快照:
参考文献 您可以在以下内容中找到一些相关讨论:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC