# Python browser automation libraries

Python browser automation libraries control a real browser from code to click, type, navigate, and read pages. A driver sends commands to the browser over the WebDriver standard or the Chrome DevTools Protocol. These libraries let test suites, scrapers, and AI agents operate websites that have no API.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Playwright](#playwright) | 135.6M | 15.1K | Nov 2026 | Apache-2.0 |
| [Selenium](#selenium) | 30.4M | 34.6K | Nov 2026 | Apache-2.0 |
| [Browser Use](#browser-use) | 7.3M | Not on GitHub | Nov 2026 | MIT |
| [browser-use-sdk](#browser-use-sdk) | 6.0M | Not on GitHub | Oct 2026 | MIT |
| [Patchright](#patchright) | 5.4M | Not on GitHub | Nov 2026 | Apache-2.0 |
| [undetected-chromedriver](#undetected-chromedriver) | 2.7M | Not on GitHub | Feb 2024 | GPL-3.0 |
| [Stagehand](#stagehand) | 1.8M | Not on GitHub | Nov 2026 | MIT |
| [SeleniumBase](#seleniumbase) | 1.2M | Not on GitHub | Nov 2026 | MIT |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[Playwright](#playwright) has the most monthly downloads in this comparison, at 129.4M.

## Capabilities

| Library | Synchronous entry point | Hosted browser service required |
| --- | --- | --- |
| [Playwright](#playwright) | Yes | No |
| [Selenium](#selenium) | Yes | No |
| [Browser Use](#browser-use) | Yes | No |
| [browser-use-sdk](#browser-use-sdk) | Yes | Yes |
| [Patchright](#patchright) | Yes | No |
| [undetected-chromedriver](#undetected-chromedriver) | Yes | No |
| [Stagehand](#stagehand) | No | No |
| [SeleniumBase](#seleniumbase) | Yes | No |

## Libraries

### Playwright

[GitHub](https://github.com/microsoft/playwright-python) · [PyPI](https://pypi.org/project/playwright) · [Docs](https://playwright.dev/python/docs/library)

Automates Chromium, Firefox, and WebKit through a shared Python API.

- Downloads / mo: 135.6M
- Stars: 15.1K
- Last release: 1.65.2
- License: Apache-2.0
- Capabilities: [From the Playwright docs](https://playwright.dev/python/docs/library)

**Strengths**

- **Waits before acting on elements.** Actions wait for the relevant element checks before running.
- **Supports multiple browser engines.** Automate Chromium, Firefox, and WebKit through the same library.

**Watch out for**

- **Browser binaries track package versions.** Install the browser binaries matching the Playwright package version.

```sh
python3.11 -m pip install playwright==1.65.2
python3.11 -m playwright install chromium
```

**scrapy-plugins/scrapy-playwright** (1.5K stars)

[scrapy-plugins/scrapy-playwright](https://github.com/scrapy-plugins/scrapy-playwright) 

```python
async def _create_browser_context(
    self,
    name: str,
    context_kwargs: Optional[dict],
    spider: Optional[Spider] = None,
) -> BrowserContextWrapper:
    """Create a new context, also launching a local browser or connecting
    to a remote one if necessary.
    """
    acquired = False
    if hasattr(self, "context_semaphore"):
        await self.context_semaphore.acquire()
        acquired = True
    try:
        context_kwargs = context_kwargs or {}
        persistent = remote = False
        if context_kwargs.get(PERSISTENT_CONTEXT_PATH_KEY):
            context = await self.browser_provider.launch_persistent_context(context_kwargs)
            persistent = True
        else:
            await self._maybe_launch_browser()
            context = await self.browser.new_context(**context_kwargs)
            remote = bool(self.config.cdp_url or self.config.connect_url)
    except Exception:
        if acquired:
            self.context_semaphore.release()
        raise

    context.on(
        "close", self._make_close_browser_context_callback(name, persistent, remote, spider)
    )
    self.stats.inc_value("playwright/context_count")
    self.stats.inc_value(f"playwright/context_count/persistent/{persistent}")
    self.stats.inc_value(f"playwright/context_count/remote/{remote}")
    logger.debug(
        "Browser context started: '%s' (persistent=%s, remote=%s)",
        name,
        persistent,
        remote,
        extra={
            "spider": spider,
            "context_name": name,
            "persistent": persistent,
            "remote": remote,
        },
    )
    if self.config.navigation_timeout_ms is not None:
        context.set_default_navigation_timeout(self.config.navigation_timeout_ms)
    self.context_wrappers[name] = BrowserContextWrapper(
        context=context,
        semaphore=asyncio.Semaphore(value=self.config.max_pages_per_context),
        persistent=persistent,
    )
    self._set_stats_max_concurrent_context_count()
    return self.context_wrappers[name]
```

[scrapy_playwright/handler.py](https://github.com/scrapy-plugins/scrapy-playwright/blob/3d513d6b1e707db7294fcf9df2e5a3feb3428e62/scrapy_playwright/handler.py) · [More projects using Playwright →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20playwright%20for%20browser%20context%20lifecycle%2C%20robust%20element%20actions%2C%20cookie%20cleanup%2C%20navigation%20and%20HTML%20form%20submission&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from playwright.sync_api import sync_playwright

with sync_playwright() as client:
    browser = client.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")
    browser.close()

```

From [README.md](https://playwright.dev/python/docs/api/class-browser)

### Selenium

[GitHub](https://github.com/SeleniumHQ/selenium) · [PyPI](https://pypi.org/project/selenium) · [Docs](https://www.selenium.dev/selenium/docs/api/py/api.html)

Automates browser interactions through WebDriver.

- Downloads / mo: 30.4M
- Stars: 34.6K
- Last release: 4.53.0
- License: Apache-2.0
- Capabilities: [From the Selenium docs](https://www.selenium.dev/selenium/docs/api/py/api.html)

**Strengths**

- **Finds compatible drivers automatically.** Selenium Manager finds the driver and downloads a browser when needed.
- **Queues browser input actions.** Queue pointer actions and run them together with perform.

**Watch out for**

- **Mixed waits change timeout behavior.** Mixing implicit and explicit waits produces unpredictable wait times.

```sh
python3.11 -m pip install selenium==4.53.0
```

**seleniumbase/SeleniumBase** (13.3K stars)

[seleniumbase/SeleniumBase](https://github.com/seleniumbase/SeleniumBase) 

```python
def hover_element_and_double_click(
    driver,
    element,
    click_selector,
    click_by="css selector",
    timeout=settings.SMALL_TIMEOUT,
):
    _reconnect_if_disconnected(driver)
    start_ms = time.time() * 1000.0
    stop_ms = start_ms + (timeout * 1000.0)
    hover = ActionChains(driver).move_to_element(element)
    for x in range(int(timeout * 10)):
        try:
            hover.perform()
            element_2 = driver.find_element(by=click_by, value=click_selector)
            actions = ActionChains(driver)
            actions.move_to_element(element_2)
            actions.double_click(element_2)
            actions.perform()
            return element_2
        except Exception:
            now_ms = time.time() * 1000.0
            if now_ms >= stop_ms:
                break
            time.sleep(0.1)
    plural = "s"
    if timeout == 1:
        plural = ""
    message = "Element {%s} was not present after %s second%s!" % (
        click_selector,
        timeout,
        plural,
    )
    timeout_exception(NoSuchElementException, message)
```

[seleniumbase/fixtures/page_actions.py](https://github.com/seleniumbase/SeleniumBase/blob/4266bb6d8a3ca4a8e0dc498920e5735a6b1d0347/seleniumbase/fixtures/page_actions.py) · [More projects using Selenium →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20selenium%20for%20browser%20context%20lifecycle%2C%20robust%20element%20actions%2C%20cookie%20cleanup%2C%20navigation%20and%20HTML%20form%20submission&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from selenium import webdriver

driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
finally:
    driver.quit()

```

From [first_script.py](https://pypi.org/pypi/selenium/4.53.0/json)

### Browser Use

[GitHub](https://github.com/browser-use/browser-use) · [PyPI](https://pypi.org/project/browser-use) · [Docs](https://docs.browser-use.com)

Runs a browser agent on Pydantic AI against cloud or local Chrome.

- Downloads / mo: 7.3M
- Last release: 1.0.6
- License: MIT
- Capabilities: [From the Browser Use docs](https://docs.browser-use.com)

```sh
python3.11 -m pip install browser-use==1.0.6
```

**Quickstart**

```python
from browser_use import Agent

result = Agent("Open https://example.com and return its title").run_sync()
print(result.final_result())

```

From [README.md](https://pypi.org/pypi/browser-use/1.0.6/json) · [Find projects using Browser Use →](https://dashboard.exa.ai/playground/search?q=browser-use%20GitHub%20projects)

### browser-use-sdk

[GitHub](https://github.com/browser-use/sdk) · [PyPI](https://pypi.org/project/browser-use-sdk) · [Docs](https://github.com/browser-use/browser-use/blob/main/skills/cloud/references/api-v4.md)

Calls the Browser Use cloud API from Python.

- Downloads / mo: 6.0M
- Last release: 3.12.1
- License: MIT
- Capabilities: [From the browser-use-sdk docs](https://github.com/browser-use/browser-use/blob/main/skills/cloud/references/api-v4.md)

```sh
python3.11 -m pip install browser-use-sdk==3.12.1
```

**Quickstart**

```python
from browser_use_sdk.v4 import BrowserUse

with BrowserUse() as client:
    created = client.runs.create("Open https://example.com and return its title")
    result = client.runs.wait_for_completion(created.id)
    print(result.result)

```

From [README.md](https://pypi.org/pypi/browser-use-sdk/3.12.1/json) · [Find projects using browser-use-sdk →](https://dashboard.exa.ai/playground/search?q=browser-use-sdk%20GitHub%20projects)

### Patchright

[GitHub](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python) · [PyPI](https://pypi.org/project/patchright)

Patches Playwright-compatible Chromium automation.

- Downloads / mo: 5.4M
- Last release: 1.64.4
- License: Apache-2.0
- Capabilities: [From the Patchright docs](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python)

```sh
python3.11 -m pip install patchright==1.64.4
python3.11 -m patchright install chromium
```

**unclecode/crawl4ai** (87.5K stars)

[unclecode/crawl4ai](https://github.com/unclecode/crawl4ai) 

```python
async def retrieve_console_messages(self, page: UndetectedPage) -> List[Dict]:
    """Retrieve captured console messages and errors from the page"""
    messages = []

    try:
        # Get console messages
        console_messages = await page.evaluate(
            "() => { const msgs = window.__capturedConsole || []; window.__capturedConsole = []; return msgs; }",
            isolated_context=False
        )
        messages.extend(console_messages)

        # Get errors
        errors = await page.evaluate(
            "() => { const errs = window.__capturedErrors || []; window.__capturedErrors = []; return errs; }",
            isolated_context=False
        )
        messages.extend(errors)

        # Convert timestamps from JS to Python format
        for msg in messages:
            if 'timestamp' in msg and isinstance(msg['timestamp'], (int, float)):
                msg['timestamp'] = msg['timestamp'] / 1000.0  # Convert from ms to seconds

    except Exception:
        # If retrieval fails, return empty list
        pass

    return messages
```

[crawl4ai/browser_adapter.py](https://github.com/unclecode/crawl4ai/blob/bf0c7925e21992af972039672fecd8e85163b575/crawl4ai/browser_adapter.py) · [More projects using Patchright →](https://dashboard.exa.ai/playground/search?q=patchright%20GitHub%20projects)

**Quickstart**

```python
from patchright.sync_api import sync_playwright

with sync_playwright() as client:
    browser = client.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")
    browser.close()

```

From [README.md](https://pypi.org/pypi/patchright/1.64.4/json)

### undetected-chromedriver

[GitHub](https://github.com/ultrafunkamsterdam/undetected-chromedriver) · [PyPI](https://pypi.org/project/undetected-chromedriver)

Starts a patched Chromium driver that stays compatible with Selenium.

- Downloads / mo: 2.7M
- Last release: 3.5.5
- License: GPL-3.0
- Capabilities: [From the undetected-chromedriver docs](https://github.com/ultrafunkamsterdam/undetected-chromedriver)

```sh
python3.11 -m pip install undetected-chromedriver==3.5.5
```

**ed-donner/agents** (6.6K stars)

[ed-donner/agents](https://github.com/ed-donner/agents) 

```python
def fetch_js_website(url: str, *, headless: bool = True, timeout: int = 30) -> str:
    """
    Scrape the visible text of a JavaScript-rendered webpage.

    Launches a headless Chrome instance via undetected-chromedriver so that
    sites protected by Cloudflare, Akamai, or similar bot-detection don't
    block the request.  The browser fully renders the page (including JS),
    waits for the <body> element, and returns its inner text.

    Args:
        url:      The webpage URL to scrape.
        headless: Run Chrome without a visible window (default True).
        timeout:  Max seconds to wait for the page to load.

    Returns:
        The visible text content of the page body.
    """
    print(f"Scraper: launching browser for {url}")

    options = uc.ChromeOptions()
    options.page_load_strategy = "eager"
    if headless:
        options.add_argument("--headless=new")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")
    options.add_argument("--disable-gpu")
    options.add_argument("--disable-extensions")
    options.add_argument(
        "--user-agent=Mozilla/5.0 (X11; Linux x86_64) "
        "AppleWebKit/537.36 (KHTML, like Gecko) "
        "Chrome/131.0.0.0 Safari/537.36"
    )

    driver = uc.Chrome(options=options, use_subprocess=False, version_main=144)
    driver.set_page_load_timeout(timeout)

    try:
        print(f"Scraper: navigating to {url}")
        start = time.perf_counter()
        try:
            driver.get(url)
        except Exception:
            # Timeout on page load is expected for heavy sites; the body
            # may still be available thanks to the 'eager' load strategy.
            pass
        elapsed = time.perf_counter() - start
        print(f"Scraper: page response received ({elapsed:.1f}s), waiting for DOM...")

        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.TAG_NAME, "body"))
        )
        # SPA sites hydrate after body appears — wait until text is non-empty
        WebDriverWait(driver, 20).until(
            lambda d: len(d.find_element(By.TAG_NAME, "body").text.strip()) > 100
        )

        content = driver.find_element(By.TAG_NAME, "body").text
    finally:
        driver.quit()

    word_count = len(content.split())
    print(f"Scraper: done — {word_count} words scraped from {url}")

    return content
```

[5_agent_frameworks/community_contributions/martinsawojide/job_cv_agent/website_scraper.py](https://github.com/ed-donner/agents/blob/3ec407e96c3467344d043403fa15f949f9fadff0/5_agent_frameworks/community_contributions/martinsawojide/job_cv_agent/website_scraper.py) · [More projects using undetected-chromedriver →](https://dashboard.exa.ai/playground/search?q=undetected-chromedriver%20GitHub%20projects)

**Quickstart**

```python
import undetected_chromedriver as uc

driver = uc.Chrome()
try:
    driver.get("https://example.com")
finally:
    driver.quit()

```

From [__init__.py](https://api.github.com/repos/ultrafunkamsterdam/undetected-chromedriver/contents/undetected_chromedriver/__init__.py)

### Stagehand

[GitHub](https://github.com/browserbase/stagehand) · [PyPI](https://pypi.org/project/stagehand) · [Docs](https://docs.stagehand.dev)

Builds browser agents on Browserbase.

- Downloads / mo: 1.8M
- Last release: 4.4.0
- License: MIT
- Capabilities: [From the Stagehand docs](https://docs.stagehand.dev)

```sh
python3.11 -m pip install stagehand==4.4.0
```

**Quickstart**

```python
import asyncio
import os
from stagehand import Stagehand, local_browser

async def main():
    browser = await local_browser.launch(headless=True)
    try:
        client = await Stagehand.create(
            browser=browser, model="openai/gpt-5.4-mini",
            model_api_key=os.environ["OPENAI_API_KEY"],
        )
        try:
            page = (await browser.context.pages())[0]
            await page.goto("https://example.com")
        finally:
            await client.close()
    finally:
        await browser.close()

asyncio.run(main())

```

From [README.md](https://pypi.org/pypi/stagehand/4.4.0/json) · [Find projects using Stagehand →](https://dashboard.exa.ai/playground/search?q=stagehand%20GitHub%20projects)

### SeleniumBase

[GitHub](https://github.com/seleniumbase/SeleniumBase) · [PyPI](https://pypi.org/project/seleniumbase) · [Docs](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md)

Provides a framework for web crawling, scraping, and testing with pytest support.

- Downloads / mo: 1.2M
- Last release: 4.58.1
- License: MIT
- Capabilities: [From the SeleniumBase docs](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/method_summary.md)

```sh
python3.11 -m pip install seleniumbase==4.58.1
```

**Quickstart**

```python
from seleniumbase import SB

with SB() as browser:
    browser.open("https://example.com")

```

From [method_summary.md](https://pypi.org/pypi/seleniumbase/4.58.1/json) · [Find projects using SeleniumBase →](https://dashboard.exa.ai/playground/search?q=seleniumbase%20GitHub%20projects)

## FAQ

### Which Python browser automation library should I use?

[Playwright](#playwright) suits new automation across Chromium, Firefox, and WebKit with automatic waiting. [Selenium](#selenium) suits teams with existing WebDriver suites or grid infrastructure. [Browser Use](#browser-use) suits AI agents that operate a browser from natural-language tasks.

### Playwright vs Selenium: which should I use?

[Playwright](#playwright) drives browsers through its own protocol and waits for elements automatically. [Selenium](#selenium) drives browsers through the WebDriver standard and supports remote grids of many browser versions.

### What is Browser Use?

[Browser Use](#browser-use) is a browser agent built on Pydantic AI that drives Chrome over the DevTools Protocol. The [browser-use-sdk](#browser-use-sdk) package calls the hosted Browser Use cloud API instead.

### How do I use Selenium with Python?

Install [Selenium](#selenium), create a driver for a browser such as Chrome, and call its find and click methods on page elements. Selenium Manager downloads a matching browser driver automatically.

### How do I use Playwright with Python?

Install [Playwright](#playwright) and run its install command to download browser builds. Scripts then launch a browser, open a page, and act on locators through the sync or async API.

### What is SeleniumBase?

[SeleniumBase](#seleniumbase) is a framework on top of Selenium for web crawling, scraping, and testing. It integrates with pytest and adds its own helper methods.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python browser automation libraries Playwright Selenium Splinter MechanicalSoup examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
