How to handle cloudflare turnstile on form recaptcha with selenium / seleniumbase?

1.2k Views Asked by At

I'm trying to login to this website: https://visa.vfsglobal.com/are/en/fra/login with selenium, but I cannot bypass the Cloudflare Turnstile CAPTCHA.

My script uses seleniumbase with undetectable options:

with SB(uc=True, uc_cdp_events=True, undetectable=True, undetected=True) as sb:
    sb.open("https://visa.vfsglobal.com/are/en/fra/login")

After running the script, even if I click the checkbox manually, it fails:

enter image description here

How can I fix this?

1

There are 1 best solutions below

1
On BEST ANSWER

Here's the script for that:

from seleniumbase import SB

with SB(uc=True) as sb:
    sb.driver.uc_open_with_reconnect(
        "https://visa.vfsglobal.com/are/en/fra/login",
        reconnect_time=12
    )

That page has a long initial load, so you need to use uc_open_with_reconnect() with a longer reconnect_time so that the page finishes loading before the driver reconnects. It's one of the methods covered in the UC Mode YouTube video about it: https://www.youtube.com/watch?v=5dMFI3e85ig

On some forms where clicking the checkbox is required, add these lines into the with block:

sb.driver.uc_switch_to_frame("iframe")
sb.driver.uc_click("span.mark")