Skip to content
Guide

SeleniumBase UC Mode Not Working on Cloudflare in 2026: Errors, Fixes and Alternatives

NSLSolver TeamPublished Updated 9 min read

SeleniumBase UC Mode usually fails on Cloudflare for four reasons: it runs headless (the PyAutoGUI click helpers cannot work), it runs on a Linux server without a display or on a datacenter IP, it reconnects WebDriver while Cloudflare is still checking, or the installed version predates Cloudflare's latest Turnstile change. Upgrade SeleniumBase, switch to CDP Mode with sb.activate_cdp_mode(url) and sb.solve_captcha(), use SB(uc=True, xvfb=True) on Linux, and test from a cleaner IP. If the checkbox still loops, get a Turnstile token from a solver API instead.

UC Mode (uc=True) hides Selenium by renaming chromedriver's DevTools variables, launching Chrome before attaching chromedriver, and disconnecting chromedriver during sensitive actions. The SeleniumBase docs now present CDP Mode as its successor, and in March 2026 the maintainer closed the long-running UC Mode tracking issue saying CDP Mode makes the older UC Mode code obsolete. Many scripts that broke in 2026 are simply still written the old way.

Quick answer: match your SeleniumBase error to the fix

These are the messages and symptoms people hit most with UC Mode and CDP Mode on Cloudflare. Find yours, then jump to the matching fix.

Exception: PyAutoGUI can't be used in headless mode!
uc_gui_* methods need a real screen. Remove headless=True / headless2=True. On Linux servers use SB(uc=True, xvfb=True), which runs a virtual display that PyAutoGUI can click on.
uc_gui_click_captcha() runs but nothing gets clicked
SeleniumBase did not detect a CAPTCHA, or clicked too early. The method returns silently when the page source has no Turnstile markers. Wait for the widget to render, upgrade SeleniumBase, or in CDP Mode try sb.solve_captcha(), which clicks via CDP.
Turnstile checkbox clicked, then "Verify you are human" again (loop)
The click landed but Cloudflare still scored the session as a bot. Usually the IP (datacenter) or a WebDriver reconnect during the check. Use CDP Mode, try incognito=True, raise reconnect_time, and test from a residential IP.
Works on Windows or macOS, fails on a Linux server
No GUI and often a datacenter IP. The maintainer's own status table marked "Linux without GUI, non-residential IP" as failing. Use xvfb=True with the SB() manager and a residential or cleaner proxy.
Exception: PyAutoGUI cannot click on point (x, y) outside screen.
The checkbox coordinates are off the virtual screen. The browser window is larger than, or positioned outside, the display. Keep default window settings under Xvfb and do not move the window off-screen.
UC Mode can't be used with Chrome-Headless-Shell!
binary_location="chs" is incompatible with UC Mode. Use regular Chrome (the default) for UC or CDP Mode.
NOTE: You must install tkinter on Linux to use MouseInfo.
PyAutoGUI's dependency is missing system packages. Run sudo apt-get install python3-tk python3-dev, as the message says, then retry.
Some sites IP-block you for hours after a failed run
You were caught with regular WebDriver. The CDP Mode docs warn that some sites block for 36 hours or more. Open the page with activate_cdp_mode(url) so WebDriver never touches it, and only reconnect when it is safe.

Why UC Mode stops passing Cloudflare

SeleniumBase has chased Cloudflare's Turnstile changes release after release. The UC Mode tracking issue (#2865) is a useful history: in June 2024 Cloudflare's update made uc_click() ineffective for Turnstile checkboxes, which is why the PyAutoGUI-based uc_gui_* methods exist, and further Cloudflare changes required upgrades to 4.29.2, 4.30.1 and 4.32.5. The current release on PyPI is 4.59.2 (2026-11-29, Python 3.10+). The root causes have stayed the same:

  • Headless mode. The UC Mode docs state that UC Mode may be detectable in headless mode and that PyAutoGUI does not work in headless mode, so every uc_gui_* call fails there.
  • No display on Linux. PyAutoGUI needs an X display. The SB() manager starts Xvfb for you; the Driver() manager does not, because it has no teardown step to clean it up.
  • IP reputation. In July 2024 the maintainer published a status table: macOS, Windows and Linux with a GUI on a residential IP passed, while Linux without a GUI on a non-residential IP failed.
  • WebDriver reconnecting too early. UC Mode is only stealthy while chromedriver is disconnected. If it reconnects while Turnstile's spinner is still running, the check can see it; the maintainer's advice is a reconnect_time high enough that the spinner has stopped.
  • Old code paths. driver.get(url) in UC Mode only switches to uc_open_with_reconnect() if a pre-check detects anti-bot protection, and driver.default_get(url) has no stealth at all.

Fix 1: upgrade and move to CDP Mode

Run pip install -U seleniumbase first: an old version against a new Turnstile is the cheapest problem to rule out. Then stop opening protected pages with WebDriver. sb.activate_cdp_mode(url) disconnects WebDriver and drives Chrome through the DevTools Protocol (calling sb.goto(url) from UC Mode now does the same). In CDP Mode, sb.solve_captcha() clicks the CAPTCHA with CDP and is documented as handling CAPTCHAs that are not bypassed automatically; sb.cdp.gui_click_captcha() is the PyAutoGUI variant.

If you do not need WebDriver at all, Pure CDP Mode skips it entirely: from seleniumbase import sb_cdp, then sb = sb_cdp.Chrome(). Note the docs' warning that reconnecting WebDriver (sb.reconnect() or sb.connect()) lets anti-bot systems detect you again, so only reconnect after you are through.

cdp_mode_turnstile.py
from seleniumbase import SB

URL = "https://example.com/login"

# CDP Mode: WebDriver is disconnected, actions go through the DevTools Protocol
with SB(uc=True, test=True, locale="en") as sb:
    sb.activate_cdp_mode(URL)
    sb.sleep(2)            # let the non-interactive check run first
    sb.solve_captcha()     # CDP click; only acts if a CAPTCHA is still there
    sb.sleep(2)
    print(sb.get_title())
    print(sb.cdp.get_user_agent())

Fix 2: uc_gui_click_captcha() or uc_gui_handle_captcha() does not click

The two helpers work differently. uc_gui_click_captcha(frame="iframe", retry=False, blind=False) moves the real mouse to the checkbox with PyAutoGUI and clicks. uc_gui_handle_captcha(frame="iframe") uses the keyboard instead, pressing TAB until the checkbox has focus and then SPACE. Both only act when the page source contains Cloudflare or reCAPTCHA markers; otherwise they return without doing anything, which looks like "it didn't click". Work through this list:

  • Call them after the widget has rendered: open with sb.uc_open_with_reconnect(url, reconnect_time=4) or add sb.sleep() before the call.
  • Make sure you are not headless and, on Linux, that a display exists (xvfb=True with SB()).
  • Do not move or resize the window outside the screen; PyAutoGUI raises "cannot click on point ... outside screen".
  • If the mouse click is flagged, try uc_gui_handle_captcha(); if focus lands in the wrong place, go back to the mouse version.
  • In CDP Mode all three work (SeleniumBase's raw_cf.py example shows each one); sb.solve_captcha() clicks with CDP Input.dispatchMouseEvent and needs no PyAutoGUI or display.
  • uc_gui_click_cf() and uc_gui_handle_cf() still exist as Turnstile-only variants, but the docs list them as commented-out aliases: the captcha versions auto-detect the type.

Fix 3: Linux servers, headless and Xvfb

On a server, the working combination is the SB() context manager with uc=True and xvfb=True and no headless flag. The UC Mode docs note that Xvfb is already enabled by default on Linux when you do not change headed or headless settings, but passing xvfb=True makes it explicit. If you must use Driver(), start your own virtual display first, as the maintainer explained in discussion #2877. If PyAutoGUI exits with the MouseInfo tkinter note, install python3-tk and python3-dev.

Proxies go in the same call: proxy="USER:PASS@SERVER:PORT" is supported directly. Add incognito=True when a site still detects you; the docs say some websites can detect you without it.

linux_uc_mode.py
from seleniumbase import SB

# Linux server without a desktop: SB() starts the Xvfb virtual display,
# Driver() does not. Do NOT pass headless=True: PyAutoGUI needs a real screen.
with SB(uc=True, xvfb=True, test=True, incognito=True,
        proxy="user:pass@proxy.example.com:8080") as sb:
    sb.uc_open_with_reconnect("https://example.com/login", reconnect_time=4)
    sb.uc_gui_click_captcha()      # mouse click via PyAutoGUI
    # sb.uc_gui_handle_captcha()   # alternative: TAB + SPACE via PyAutoGUI
    sb.sleep(3)
    print(sb.get_title())

Fix 4: the Turnstile checkbox keeps looping

A loop means the click works mechanically but the score is still too low. Raise reconnect_time (the default in SeleniumBase's constants is 2 seconds) so WebDriver stays disconnected until the check finishes, or avoid WebDriver entirely with CDP Mode. Change one variable at a time: residential versus datacenter IP, incognito=True, locale="en". If you were caught with plain WebDriver earlier, the site may still be blocking that IP: the CDP Mode docs warn that some sites block for 36 hours or more.

When to switch to a managed solver

SeleniumBase is excellent when you need a real browser session and run it on a desktop or a residential connection. It becomes expensive when Turnstile only clears on residential IPs with a virtual display, when each Cloudflare change means an upgrade-and-redeploy cycle, or when PyAutoGUI's file lock serialises your parallel workers because only one process can control the mouse at a time.

For a Turnstile widget on a form, you do not need to win the click at all: a solver returns a valid token and you put it in the cf-turnstile-response field. Only automate sites you own or are authorised to access, and respect their terms and rate limits.

NSLSolver example: a Turnstile token inside SeleniumBase

Keep SeleniumBase for navigation and form filling, and replace only the checkbox step. POST the widget's site_key (the data-sitekey attribute of .cf-turnstile) and the page url to NSLSolver with type turnstile; the response contains a token you set as the cf-turnstile-response value before submitting. Tokens come back in about 250 ms on average, cost $0.80 per 1,000, only successful solves are billed, and sign-ups with Google, Gmail or Proton get free credit with no card.

Three details matter. Submit within 300 seconds and only once, because Turnstile tokens are single-use. If the widget sets data-action or data-cdata, send them as action and cdata. If the site reads the token from a JavaScript callback rather than the hidden input, call that callback with the token. For a full-page "Just a moment..." challenge rather than a widget, use type challenge, which returns cf_clearance. NSLSolver does not solve reCAPTCHA v2 or hCaptcha.

seleniumbase_nslsolver.py
import json

import requests
from seleniumbase import SB

API_KEY = "nsl_YOUR_API_KEY"
URL = "https://target-site.com/login"


def turnstile_token(site_key: str, page_url: str) -> str:
    resp = requests.post(
        "https://api.nslsolver.com/solve",
        headers={"X-API-Key": API_KEY},
        json={"type": "turnstile", "site_key": site_key, "url": page_url},
        timeout=120,
    )
    resp.raise_for_status()
    return resp.json()["token"]


with SB(uc=True, test=True) as sb:
    sb.activate_cdp_mode(URL)
    site_key = sb.cdp.get_attribute(".cf-turnstile", "data-sitekey")
    token = turnstile_token(site_key, URL)

    # Put the token where the form expects it, then submit within 300 seconds
    sb.cdp.evaluate(
        "document.querySelectorAll('[name=\"cf-turnstile-response\"]')"
        f".forEach(el => el.value = {json.dumps(token)})"
    )
    sb.cdp.click('button[type="submit"]')

Full /solve API reference

Related: the Cloudflare Turnstile solver API for integration details, pay-per-success pricing, undetected-chromedriver not working for the library UC Mode grew out of, solving Turnstile in Python for a requests-only flow, and the Turnstile error code list if the widget shows a numeric error.

Frequently asked questions

Why is SeleniumBase UC Mode not working on Cloudflare anymore?

Usually because it runs headless, runs on a Linux server without a display or on a datacenter IP, reconnects WebDriver before Turnstile finishes, or is an older version than Cloudflare's latest change. Upgrade, switch to CDP Mode with sb.activate_cdp_mode(url) and sb.solve_captcha(), and use SB(uc=True, xvfb=True) on Linux.

Why does uc_gui_click_captcha() not click the Turnstile checkbox?

It needs a headed browser and a display, and it returns silently when it does not detect a CAPTCHA in the page source. Call it after the widget renders, never in headless mode, with xvfb=True on Linux, or in CDP Mode try sb.solve_captcha(), which needs no display.

What is the difference between uc_gui_click_captcha() and uc_gui_handle_captcha()?

uc_gui_click_captcha() moves the real mouse to the checkbox with PyAutoGUI and clicks it. uc_gui_handle_captcha() uses the keyboard, tabbing to the checkbox and pressing space. If one is flagged or misses, try the other.

Can SeleniumBase UC Mode run headless?

Not for CAPTCHA clicks. The docs say UC Mode may be detectable in headless mode and that PyAutoGUI does not work headless; SeleniumBase raises "PyAutoGUI can't be used in headless mode!". On Linux, use the Xvfb virtual display through the SB() manager.

Is UC Mode deprecated in favour of CDP Mode?

The docs call CDP Mode the successor to plain UC Mode, and the maintainer closed the UC Mode tracking issue in March 2026 saying CDP Mode makes the older UC Mode code obsolete. You still start with SB(uc=True), then call sb.activate_cdp_mode(url).

What does uc_open_with_reconnect() do?

It opens the URL while chromedriver is disconnected, waits reconnect_time seconds (2 by default), then reconnects so you can issue commands. Set it high enough that the Turnstile spinner has stopped; "breakpoint" pauses for manual action.

Can I use NSLSolver with SeleniumBase?

Yes. Read the widget's data-sitekey, POST it with the page url to NSLSolver's /solve endpoint as type turnstile, then set the returned token as cf-turnstile-response and submit within 300 seconds. For a full-page Cloudflare challenge, use type challenge, which returns cf_clearance.

Skip the checkbox, keep your SeleniumBase script

Get a valid Turnstile token in about 250 ms and drop it into the form. Free credit with Google, Gmail or Proton sign-up, no card, and you only pay for successful solves.