seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.46k stars 910 forks source link

Can't get passed cloudflare using UC mode #2715

Closed Ali-Flt closed 2 months ago

Ali-Flt commented 2 months ago

Hey, I am trying to get passed the cloudflare human check of this link: https://visa.vfsglobal.com/IRN/en/fra/login I tried using this example from the documents:

from seleniumbase import SB

def open_the_turnstile_page(sb):
    url = "https://visa.vfsglobal.com/IRN/en/fra/login"
    sb.driver.uc_open_with_reconnect(url, reconnect_time=2)

def click_turnstile_and_verify(sb):
    sb.switch_to_frame("iframe")
    sb.driver.uc_click("span.mark")
    sb.assert_element("img#captcha-success", timeout=3)

with SB(uc=True, test=True) as sb:
    open_the_turnstile_page(sb)
    try:
        click_turnstile_and_verify(sb)
    except Exception:
        open_the_turnstile_page(sb)
        click_turnstile_and_verify(sb)
    sb.set_messenger_theme(location="top_left")
    sb.post_message("SeleniumBase wasn't detected", duration=3)

but it got detected. Any tips? Or is it just not possible to pass the cloudflare test of this website with the current version of seleniumbase?

Thanks

mdmintz commented 2 months ago

Duplicate of https://stackoverflow.com/a/77578982/7058266

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")