I need some help. There is a 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
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 iframe in which the recaptcha is located.
To click()
on the check box associated with the captcha , as the the desired elements are within an <iframe>
so you have to:
scrollIntoView()
the reCAPTCHA checkbox 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:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.