如何使用Selenium和Python的Buster扩展程序绕过ReCaptcha

4

目前,我使用Selenium自动化一些流程,并需要解决Google ReCaptcha。用于解决ReCaptcha的技术是浏览器插件Buster。我使用以下方式输入Google ReCaptcha:

driver.switch_to.frame(driver.find_elements_by_tag_name("iframe")[0])
check_box = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "recaptcha-anchor")))
check_box.click()

现在我使用以下方式切换回默认的 Frame:

driver.switch_to.default_content()

我需要点击Buster图标,但是如何操作呢?

需要点击的图标:

需要点击的图标

1个回答

2

Buster 图标 位于另一个同级的<iframe>中。因此,您需要执行以下操作:

  • 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
    
    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:

recaptcha_iframe


参考资料

您可以在以下讨论中找到一些相关的内容:


结语

处理iframe下的#document的方法


3
求解按钮现在位于封闭的 Shadow DOM 内部,你代码的最后一行不再起作用。 - abbr
@abbr 有关于封闭式影子 DOM 的任何想法吗? - Nam Vu
1
@NamVu,我在Buster的Github上提交了一个关于关闭Shadow DOM的问题。Buster的作者回复说Buster不是为自动化测试脚本设计的,并删除了该问题的工单。 - abbr

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接