-1

I am working on website that contain two recaptcha v2, First one solved perfect but the next one open captcha frame but cant click the audio button. I have tried more than method to click the button of audio challenge but i cant get any solution.

enter image description here

.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()

I tried to change |driver.switch_to.frame(frames1)| from 0 to 7 but still cant click the button and show me this error:

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

Any kind of help please?

1 Answer 1

1

See you are using tagname, for iframe. so why don't you directly try, find_elements with tag_name ?

instead of this :

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

do this :

all_iframes = driver.find_elements_by_tag_name("iframe")

and then print the size of this list,

print(len(all_iframes ))

and see if it has something then iterate otherwise you will end up getting IndexError: list index out of range

The below loop is just for testing :-

for iframe in all_iframes:
    print(iframe.text)
Sign up to request clarification or add additional context in comments.

3 Comments

he print number 5
try to print the loop which I have given you above, and let me know the output.
He shows number length = 5 and print 5 empty rows !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.