Fast, Reliable & Modern
Web Automation

Playwright enables reliable end-to-end testing for modern web apps. This page demonstrates core capabilities using Python.

View Code Samples

Fast Execution

Parallelize tests with zero configuration. Playwright runs tests in parallel across all browsers.

Auto-Waiting

No more flaky tests. Playwright waits for elements to be actionable before executing actions.

Cross-Browser

Test on Chromium, Firefox, and WebKit (Safari) with a single API on Windows, Linux, and macOS.

Python Code Samples

Click on the tabs to explore different Playwright capabilities.

A simple synchronous script to launch a browser and take a screenshot.

example_basic.py
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    # Launch browser (headless=False to see UI)
    browser = p.chromium.launch(headless=False)
    page = browser.new_page()
    
    # Navigate to URL
    page.goto("https://playwright.dev/python")
    
    # Interact with page
    print(page.title())
    
    # Screenshot
    page.screenshot(path="example.png")
    
    browser.close()

Using robust Locators to find elements on the page.

locators.py
from playwright.sync_api import sync_playwright

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

    # Get by role (most accessible)
    get_started = page.get_by_role("link", name="Get Started")

    # Get by text content
    submit = page.get_by_text("Submit")

    # Get by test ID (recommended for CSS changes)
    submit = page.get_by_test_id("auth-button")

    # Chain locators
    product = page.locator(".list").get_by_text("Playwright")
    
    browser.close()

Built-in assertions to wait for conditions automatically.

assertions.py
from playwright.sync_api import expect

# Navigating and waiting for URL
page.goto("https://example.com")
expect(page).to_have_url("https://example.com/")

# Checking element visibility
locator = page.locator(".status-message")
expect(locator).to_be_visible()

# Checking text content
expect(locator).to_contain_text("Welcome")

# Checking attribute values
button = page.locator("#submit")
expect(button).to_have_attribute("type", "submit")

Capturing a trace to debug test failures visually.

trace.py
# Start tracing before creating/running the browser
context = browser.new_context()
context.tracing.start(screenshots=True, snapshots=True)

page = context.new_page()
page.goto("https://playwright.dev")

# ... perform actions ...
page.click("text=Get Started")

# Stop tracing and save the file
context.tracing.stop(path = "trace.zip")

# View trace using CLI:
# playwright show-trace trace.zip

Get Started Now

Install Playwright via pip and install the required browsers.

pip install playwright
playwright install
Read Official Docs