首页 > 解决方案 > 有没有办法从网站上点击 recaptcha 元素

问题描述

所以我试图通过硒解决验证码。首先,我尝试单击此网站https://patrickhlauke.github.io/recaptcha/上的验证码。我尝试了没有成功的 xpath 和 ID 方法。有人可以帮我吗?这是我要单击的图片, 这也是我所写的。任何帮助,将不胜感激。

from selenium import webdriver
import keyboard
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://patrickhlauke.github.io/recaptcha/")
time.sleep(3)
driver.find_element_by_xpath('//*[@id="recaptcha-anchor"]')

标签: pythonseleniumautomation

解决方案


<iframe src="https://www.google.com/recaptcha/api2/anchor?ar=1&amp;k=6Ld2sf4SAAAAAKSgzs0Q13IZhY02Pyo31S2jgOB5&amp;co=aHR0cHM6Ly9wYXRyaWNraGxhdWtlLmdpdGh1Yi5pbzo0NDM.&amp;hl=en&amp;v=5mNs27FP3uLBP3KBPib88r1g&amp;size=normal&amp;cb=ufdnmqmcxiqv" width="304" height="78" role="presentation" name="a-y2973t5aots" 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>

您的元素在 iframe 切换到它。现在你的 xpath 应该可以工作了。

driver.switch_to.frame(0)

推荐阅读