SeleniumBase
seleniumbase · seleniumbase/SeleniumBase
An MCP server and framework for browser automation, web scraping, and end-to-end testing with stealth capabilities.
📊 Browser automation framework for scraping, testing, and completing tasks with Python. Supports pytest. Stealth options. Over 100 examples.
Preview
What you can do with it
- Create automated UI tests for web applications via an agent
- Scrape dynamic content from websites while bypassing bot detection
- Automate CAPTCHA handling during web workflows
Safety check
No risky patterns found in the files we scanned.
Automated scan of the repo files. Always review code you run.
From the README
SeleniumBase
All-in-one Browser Automation Framework:Web Crawling / Testing / Scraping / Stealth
🚀 Start | 🏰 Features | 🎛️ Options | 📚 Examples | 💻 Scripts | 🗾 Locale
📗 API | 📘 Stealth API | 🔠 DesignPatterns | 🔴 Recorder | 📊 Dashboard
🎖️ GUI | 📰 TestPage | 👤 UC Mode | 🐙 CDP Mode | 📶 Charts | 🖥️ Farm
👁️ How | 🚝 Migration | 🎭 Stealthy Playwright | 🛂 MasterQA | 🚎 Tours
🤖 MCP | 🟨 JS Mgr | 🌏 Translator | 🎞️ Presenter | 🖼️ Visual | 🗂️ CPlans
📊 SeleniumBase is a complete framework for browser automation and testing with Python and pytest. Includes stealth options and other advanced features.
🐙 Stealth modes: UC Mode and CDP Mode can bypass bot-detection, handle CAPTCHAs, and call methods from the Chrome Devtools Protocol. CDP Mode includes Stealthy Playwright Mode, which makes Playwright stealthy.
📚 The SeleniumBase/examples/ folder includes over 100 ready-to-run examples. Examples that start with test_ or end with _test.py/_tests.py are specifically designed to run with pytest. Other examples run directly with raw python (those files generally start with raw_ to avoid confusion).
🥷 Stealthy examples are located in SeleniumBase/examples/cdp_mode/.
⚙️ Stealthy architecture flowchart:
(For maximum stealth, use CDP Mode, which includes Stealthy Playwright Mode)
📝 Here's a Python example that uses Pure CDP Mode (sb_cdp):(It navigates to Planet Minecraft where it bypasses the CAPTCHA)
from seleniumbase import sb_cdp
sb = sb_cdp.Chrome(incognito=True)
sb.goto("www.planetminecraft.com/account/sign_in")
sb.solve_captcha()
# "LOG IN" is enabled when the CAPTCHA is bypassed
sb.wait_for_element_absent("input[disabled]")
sb.sleep(2)
sb.quit()
python raw_cdp_planetmc.py
✅ sb.solve_captcha() handles CAPTCHAs that aren't bypassed automatically.(If called when there's no CAPTCHA on the page, then nothing happens / no-op.)
📝 This example scrapes Hacker News listings:
from seleniumbase import sb_cdp
sb = sb_cdp.Chrome()
sb.goto("https://news.ycombinator.com/submitted?id=seleniumbase")
elements = sb.find_elements("span.titleline > a")
for element in elements:
print("* %s" % element.text)
python raw_cdp_yc_news.py
📝 Here’s SeleniumBase/examples/cdp_mode/raw_cdp_methods.py:(It performs several different actions on the web page)
from seleniumbase import sb_cdp
sb = sb_cdp.Chrome(fast=True)
sb.goto("https://seleniumbase.io/demo_page")
sb.type("input", "Quickly type text!")
sb.press_keys("textarea", "Slowly type text!")
sb.click("#myButton")
sb.set_value("input#mySlider", "100")
sb.click_visible_elements("input.checkBoxClassB")
sb.select_option_by_text("#mySelect", "Set to 75%")
sb.hover_and_click("#myDropdown", "#dropOption2")
sb.click("#checkBox1")
sb.drag_and_drop("img#logo", "div#drop2")
sb.nested_click("iframe#myFrame3", ".fBox")
sb.highlight("#myButton")
sb.quit()
python raw_cdp_methods.py
ℹ️ Setting fast=True lets your automation go at full speed, which may be useful if maximum stealth isn't your goal.
📝 This example bypasses Cloudflare's challenge page with UC + CDP Mode:(If the Turnstile isn't bypassed automatically, sb.solve_captcha() handles it.)
from seleniumbase import SB
with SB(uc=True, test=True, locale="en") as sb:
sb.activate_cdp_mode()
sb.goto("https://gitlab.com/users/sign_in")
sb.sleep(2)
sb.solve_captcha()
sb.highlight('h1:contains("GitLab")')
sb.highlight('button:contains("Sign in")')
python raw_gitlab.py
🧪 End-to-End Testing examples are located in ./examples/.
🐙 Stealthy CDP Mode examples are located in ./examples/cdp_mode/.
🎭 Stealthy Playwright examples are located in ./examples/cdp_mode/playwright/.
🌐 CLI Options for Supported Chromium Browsers
💡 You can set the Chromium browser to use via command line parameters:
python SCRIPT.py --chromium # Use the unbranded Chromium browser
python SCRIPT.py --cft # Use Chrome-for-testing
python SCRIPT.py --edge # Use Microsoft Edge
python SCRIPT.py --brave # Use Brave browser
Google Chrome is the default browser. Only unbranded Chromium and Chrome-for-Testing get downloaded automatically if not already present on the system.
The Chromium browser can also be set via method args, eg: cft=True, use_chromium=True, browser="edge", browser="brave", etc. Eg:
sb = sb_cdp.Chrome(use_chromium=True)
🧪 Comprehensive E2E Testing with pytest:
📚 The SeleniumBase/examples/ folder includes over 150 ready-to-run examples of E2E testing. Examples that start with test_ or end with _test.py/_tests.py run with pytest. Other examples run d