Python 3.x 消息:没有这样的元素:无法定位元素:{quot;方法";:“css选择器”;“选择器”:“重选复选框边框”}

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绕过验证码验证,但我一直遇到这个错误

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&amp;k=6LepxvIZAAAAAPGd49tlErQ-2da9Bh-3yN_gCjul&amp;co=aHR0cHM6Ly93aGl0ZXBhZ2VzLmNvLm56OjQ0Mw..&amp;hl=en&amp;v=2Mfykwl2mlvyQZQ3PEgoH710&amp;size=normal&amp;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
    
  • 浏览器快照:


参考文献 您可以在以下内容中找到一些相关讨论:


您的对象位于“iframe”中-您需要切换到该帧,以便使用selenium识别它。。。然而,如果这个网站有验证码,它不想让你自动化它,这将是你将面临的问题的冰山一角。验证码旨在阻止机器人和自动化-如果它们不起作用,人们就不会使用它们切换到iframe对数据站点密钥有任何依赖性吗?不完全是在他需要密钥进行验证码验证之后。这是他将把它放在下面的地方。非常感谢你的帮助,代码现在可以正常工作了,没有任何麻烦。
 from selenium.webdriver.support.ui import WebDriverWait
 from selenium.webdriver.common.by import By
 from selenium.webdriver.support import expected_conditions as EC