【问题标题】:Problem with click audio challenge recaptcha v2 by using selenium使用 selenium 的点击音频挑战 recaptcha v2 的问题
【发布时间】:2023-03-19 15:42:01
【问题描述】:

我正在开发包含两个 recaptcha v2 的网站,第一个完美解决,但下一个打开验证码框架但无法单击音频按钮。我已经尝试了多种方法来单击音频挑战按钮,但我无法得到任何解决方案。

.html:

<iframe title="reCAPTCHA" src="https://www.google.com/recaptcha/api2/anchor?ar=1&amp;k=6LcMzpsUAAAAAD2JOVSS9DYyk7aSbk-KQ3KL7Nkv&amp;co=aHR0cHM6Ly9tdXFlZW0uc2E6NDQz&amp;hl=ar-ly&amp;type=image&amp;v=Q_rrUPkK1sXoHi4wbuDTgcQR&amp;theme=light&amp;size=normal&amp;cb=flmxkon1yi8a" width="304" height="78" role="presentation" name="a-fzpsv3rm6omy" frameborder="0" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox" cd_frame_id_="6857a4b8282493a9397ca67d60e7e461"></iframe>

.py:

 frames = driver.find_elements_by_tag_name("iframe")
    driver.switch_to.frame(frames[0])
    delay()
    # click on checkbox to activate recaptcha
    driver.find_element_by_xpath('/html/body/div[2]/div[3]/div[1]/div/div/span/div[1]').click()

    # switch to recaptcha audio control frame
    html = driver.find_element_by_tag_name('html')
    html.send_keys(Keys.PAGE_DOWN)

    driver.switch_to.default_content()
    frames = driver.find_element_by_xpath("/html/body/div[2]/div[4]").find_elements_by_tag_name("iframe")
    driver.switch_to.frame(frames[1])
    delay()
    # click on audio challenge
    driver.find_element_by_id("recaptcha-audio-button").click()

我试图改变 |driver.switch_to.frame(frames1)|从 0 到 7 但仍然无法单击按钮并显示此错误:

driver.switch_to.frame(frames[1])
IndexError: list index out of range

请问有什么帮助吗?

【问题讨论】:

    标签: python python-3.x selenium


    【解决方案1】:

    看到你正在使用tagname,为iframe。那你为什么不直接试试find_elementstag_name

    而不是这个:

    frames = driver.find_element_by_xpath("/html/body/div[2]/div[4]").find_elements_by_tag_name("iframe")
    

    这样做:

    all_iframes = driver.find_elements_by_tag_name("iframe")
    

    然后打印这个list的大小,

    print(len(all_iframes ))
    

    看看它是否有东西然后迭代否则你最终会得到IndexError: list index out of range

    以下循环仅用于测试:-

    for iframe in all_iframes:
        print(iframe.text)
    

    【讨论】:

    • 他打印数字 5
    • 尝试打印我上面给你的循环,并让我知道输出。
    • 他显示数字长度 = 5 并打印 5 个空行!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 2010-12-22
    • 1970-01-01
    • 1970-01-01
    • 2019-08-11
    • 2018-05-25
    • 1970-01-01
    相关资源
    最近更新 更多