繁体   English   中英

找到reCAPTCHA扩展元素,然后单击它-Python Selenium

[英]Find the reCAPTCHA extension element and click on it - Python Selenium

我需要一些帮助。 有一个URL: https : //matricula.sistemaeliterio.com.br/Candidate/Registration 我需要点击验证码复选框,然后在点击扩展徽标后:

在此处输入图片说明

在此处输入图片说明

该扩展程序可以在chrome商店中下载,网址为https://chrome.google.com/webstore/detail/buster-captcha-solver-for/mpbjkejclgfgadiemmefgebjfooflfhl

我的代码是这样的:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

options = webdriver.ChromeOptions()
#options.add_extension('driver/Block-image_v1.1.crx')
options.add_extension('driver/captcha_2.crx')
driver = webdriver.Chrome('driver/chromedriver.exe',chrome_options=options)

driver.get('https://matricula.sistemaeliterio.com.br/Candidate/Registration/bolsao?schoolYear=2020&_ga=2.197375407.1653445941.1571361668-1911282789.1571361668')

driver.find_element_by_xpath(
    '//*[@id="registration-container"]/form/div[1]/div/div[1]/div[2]/div/div[1]').click()

driver.find_element_by_xpath('//*[@id="registration-container"]/form/div[1]/div/div[1]/div[2]/div/div['
                             '2]/div/div[1]').click()

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='recaptcha-checkbox goog-inline-block recaptcha-checkbox-unchecked rc-anchor-checkbox']/div[@class='recaptcha-checkbox-border']"))).click()

time.sleep(2)

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'/html/body/div[7]/div[4]/iframe')))
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'//*[@id="solver-button"]')))

希望有人知道答案

此错误消息...

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,'/html/body/div[7]/div[4]/iframe'))) 
File "C:\Users****\Anaconda3\envs\k37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace)

...表示WebDriver无法找到所在的

要在与验证关联的复选框click() ,因为所需元素位于<iframe>因此您必须:

  • scrollIntoView() reCAPTCHA 复选框
  • 诱导WebDriverWait获得所需的帧并切换到该帧
  • 诱导WebDriverWait使所需的元素可单击
  • 您可以使用以下定位策略

    • 代码块:

       from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option('useAutomationExtension', False) driver = webdriver.Chrome(options=options, executable_path=r'C:\\WebDrivers\\chromedriver.exe') driver.get('https://matricula.sistemaeliterio.com.br/Candidate/Registration/bolsao?schoolYear=2020&_ga=2.197375407.1653445941.1571361668-1911282789.1571361668') driver.find_element_by_xpath('//*[@id="registration-container"]/form/div[1]/div/div[1]/div[2]/div/div[1]').click() driver.find_element_by_xpath('//*[@id="registration-container"]/form/div[1]/div/div[1]/div[2]/div/div[2]/div/div[1]').click() driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.g-recaptcha#captcha-form")))) WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.google.com/recaptcha/api2/anchor']"))) WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span#recaptcha-anchor"))).click() 
  • 浏览器快照:

reCAPTCHA_clicked

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM