0
with SB(uc=True, Headless=True) as sb:
    for url in urls:
        sb.uc_open_with_reconnect(url, 5)
        sb.uc_gui_handle_captcha()
        time.sleep(2)
        has_next_page = True

I'm facing a website with a CAPTCHA. In NON HEADLESS mode, that code works properly, but in headless mode, it doesn't because sb.uc_gui_handle_captcha() needs PyAutoGUI, and in headless mode, PyAutoGUI can't run.

I read in the seleniumbase documentation that the SB manager includes a special virtual display that allows for PyAutoGUI actions. How can i enable that virtual display so that my code will work properly in headless mode?

I expect that the code will run in headless mode, and that sb.uc_gui_handle_captcha() can bypass the CAPTCHA with headless mode.

1 Answer 1

0

Use the SeleniumBase Xvfb virtual display to simulate headless mode in a headless environment on Linux:

from seleniumbase import SB

with SB(uc=True, xvfb=True) as sb:
    urls = [URL1, URL2]
    for url in urls:
        sb.uc_open_with_reconnect(url, 5)
        sb.uc_gui_click_captcha()
        sb.sleep(2)
        # Do more stuff here

(Don't mix regular headless mode with UC Mode, as PyAutoGUI needs a regular browser to interact with it. Xvfb replaces headless mode in Linux environments.)

Sign up to request clarification or add additional context in comments.

3 Comments

is there a way to set display size here?
I've set the sb.cdp.set_window_rect() to 1920x1080 in a Docker container with the xvfb=True and the resize works (checked with a screenshot test). I just wonder if the cpd gui / pyautogui functions will still work since the Xvfb_launcher.sh file is set to 1280x1024x16.
You can change those dimensions with xvfb_metrics="width,height"

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.