如何与reCAPTCHA交互使用Selenium和Python解决质询按钮 [英] How to interact with the reCAPTCHA Solve the challenge button using Selenium and Python

查看:160
本文介绍了如何与reCAPTCHA交互使用Selenium和Python解决质询按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Selenium和Python与图像验证弹出窗口上的Recaptcha 解决挑战按钮进行交互.

xpath在开发工具中看起来正确,但是使用Selenium无法与其进行交互.有什么问题吗?

  WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,'//button [contains(@id,'solver-button')]'))).点​​击() 

解决方案

单击


参考

您可以在以下位置找到一些相关的讨论:


Outro

在iframe下处理#document的方式

I'm trying to interact with the recaptcha Solve the challenge button on image verification popup using Selenium and Python.

The xpath looks correct in dev tools but using Selenium unable to interact with it. What is the problem?

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[contains(@id, "solver-button")]'))).click()

解决方案

Once you click on the and get redirected to the image challenges, the picture elements are within another sibling <iframe>. So you have to:

  • Switch back to the default_content().

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • 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://www.google.com/recaptcha/api2/demo")
    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()
    driver.switch_to.default_content()
    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"//iframe[@title='recaptcha challenge']")))
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='solver-button']"))).click()
    

  • Browser Snapshot:


Reference

You can find a couple of relevant discussions in:


Outro

Ways to deal with #document under iframe

这篇关于如何与reCAPTCHA交互使用Selenium和Python解决质询按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆