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

问题描述 投票:0回答:1

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

enter image description here

enter image description here

可以在chrome商店中下载扩展名,URL 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"]')))

希望有人知道答案

python python-3.x selenium-webdriver selenium-chromedriver recaptcha
1个回答
0
投票

此错误消息...

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() the reCAPTCHA 复选框
  • WebDriverWait设置为所需的[[框架可用并切换到它]]。
  • WebDriverWait
  • 表示为所需的[[可点击的元素您可以使用以下Locator Strategies
    • 代码块:
    • 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
© www.soinside.com 2019 - 2024. All rights reserved.