# SeleniumBase

> All-in-one Python browser automation for testing, scraping, and stealth crawling

- Category: Data & Labeling / Web Scraping & Crawling
- Language: Python
- Licence: MIT
- Repository: https://github.com/seleniumbase/SeleniumBase
- Website: https://seleniumbase.io
- Canonical page: https://ai-tldr.dev/tools/seleniumbase/

## In short

SeleniumBase is an open-source Python framework that brings web testing, web crawling, scraping, and stealth automation together in one tool. You write Python scripts that drive a real Chromium browser, and the framework handles the setup, waiting, and driver management for you. It sits in the Web Scraping & Crawling category of the Data & Labeling tools and is open-source, written in Python and licensed MIT.

## Overview

SeleniumBase is an open-source Python framework that brings web testing, web crawling, scraping, and stealth automation together in one tool. You write Python scripts that drive a real Chromium browser, and the framework handles the setup, waiting, and driver management for you.

It runs on top of Selenium WebDriver and adds higher-level methods so your code stays short and readable. Most scripts can be run with pytest, pynose, or plain python, and a stealthy CDP Mode lets your browser sessions pass common bot-detection tests on sites that block normal automation.

## What it does

- CDP Mode: a stealthy Chromium automation mode that bypasses common bot-detection systems
- Stealthy Playwright Mode that connects Playwright to a SeleniumBase browser session
- High-level Python methods (open, find_elements, assert_element, and more) that reduce boilerplate over raw Selenium
- Runs the same tests with pytest, pynose, or pure python, plus a Gherkin/behave BDD format
- Command-line tools via the seleniumbase / sbase commands, including project scaffolding with sbase mkdir
- Test reporting extras like HTML reports, a dashboard, screenshots, and a demo mode for visual stepping

## Getting started

SeleniumBase installs from PyPI with pip. Install the package, verify the command-line tool, then run a script with pytest or pure Python.

1. Install SeleniumBase

   Install the main framework from PyPI. Add Playwright too if you want the Stealthy Playwright integration.

```bash
pip install seleniumbase
pip install playwright
```

2. Verify the install

   Type seleniumbase or sbase to confirm the framework installed correctly and to see the available commands.

```bash
sbase --help
```

3. Run a stealthy CDP Mode script

   Pure CDP Mode (sb_cdp) opens a stealthy Chromium browser. This short script navigates to a bot-detection page and then quits.

```python
from seleniumbase import sb_cdp

sb = sb_cdp.Chrome()
sb.goto("https://browserscan.net/bot-detection")
sb.sleep(3)
sb.quit()
```

4. Run a test with pytest

   Tests built on the BaseCase class run through pytest. Use the --demo flag to step through the actions visually.

```bash
pytest my_first_test.py --demo
```

## When to use it

- Write end-to-end UI tests for web apps and run them with pytest, with HTML reports and a dashboard
- Scrape data from pages, such as collecting listing titles and links into a Python list
- Crawl sites protected by bot-detection using the stealthy CDP Mode browser
- Connect Playwright to a stealthy SeleniumBase session for automation that needs to look like a real user
