简体   繁体   English

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

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

I need some help. 我需要一些帮助。 There is a URL: https://matricula.sistemaeliterio.com.br/Candidate/Registration . 有一个URL: https : //matricula.sistemaeliterio.com.br/Candidate/Registration I need to click checkbox Captcha then after click on the extension logo: 我需要点击验证码复选框,然后在点击扩展徽标后:

在此处输入图片说明

在此处输入图片说明

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

My code it's like this: 我的代码是这样的:

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"]')))

Hope some know the answer 希望有人知道答案

This error message... 此错误消息...

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)

...implies that the WebDriver was unable to locate the in which the is located. ...表示WebDriver无法找到所在的

To click() on the check box associated with the , as the the desired elements are within an <iframe> so you have to: 要在与验证关联的复选框click() ,因为所需元素位于<iframe>因此您必须:

  • scrollIntoView() the reCAPTCHA checkbox scrollIntoView() reCAPTCHA 复选框
  • Induce WebDriverWait for the desired frame to be available and switch to it . 诱导WebDriverWait获得所需的帧并切换到该帧
  • Induce WebDriverWait for the desired element to be clickable . 诱导WebDriverWait使所需的元素可单击
  • You can use the following Locator Strategies : 您可以使用以下定位策略

    • Code Block: 代码块:

       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() 
  • Browser Snapshot: 浏览器快照:

reCAPTCHA_clicked

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

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