Microsoft's browser automation library for Python. Automates Chromium, Firefox, and WebKit. Current version is 1.58.0 (Jan 2026). Requires Python >=3.9. Critical two-step install: pip install playwright followed by playwright install to download browser binaries — omitting the second step causes BrowserType.launch: Executable doesn't exist error.
pip install playwrightVerified import paths — ran on the pinned version, not inferred.
Basic sync pattern. Use locators (get_by_role, get_by_label) not raw CSS selectors.
Two-step install: pip install playwright then playwright install. In CI/Docker: playwright install --with-deps to also install OS-level dependencies.
Pin playwright<1.51 for Python 3.8 environments.
Use a dedicated accessibility testing library like Axe. The Playwright docs link to Axe integration guides.
Update Dockerfiles to use: FROM mcr.microsoft.com/playwright/python:v1.58.0-jammy
Pick one: from playwright.sync_api import sync_playwright for sync code, or from playwright.async_api import async_playwright for async code. Never import from the wrong module.
Replace page.click('#submit') with page.get_by_role('button', name='Submit').click(). Use page.get_by_label() for form inputs, page.get_by_test_id() for data-testid attributes.After every pip install --upgrade playwright, run playwright install again.
To resolve this, consider using a slightly older, officially supported Python version (e.g., Python 3.12 or 3.11, depending on current Playwright release cycles). Alternatively, wait for Playwright to release compatible distributions for your Python version and platform. Always check Playwright's official documentation or PyPI page for supported Python versions and their compatible environments.
After installing the Python package (`pip install playwright`), you must also install the browser binaries by running `playwright install` in your terminal. For specific browsers, use `playwright install chromium`, `playwright install firefox`, or `playwright install webkit`.
Install the Playwright Python package using `pip install playwright`. If it's already installed, ensure your Python environment is correctly activated and there isn't a file named `playwright.py` in your project directory that might be shadowing the actual library.
Increase the timeout for the specific action or globally. For an action, pass a `timeout` argument (e.g., `page.goto('url', timeout=60000)`). For waiting for a selector, use `page.locator('#element').wait_for(timeout=10000)`. Avoid arbitrary `time.sleep()` calls and rely on Playwright's auto-waiting capabilities or explicit waits for conditions.Ensure that the web server or application you are trying to access is running and accessible at the specified URL and port from within the environment where Playwright is executing. In CI environments, this often means properly setting up and waiting for a `webServer` in your Playwright configuration or ensuring service dependencies are met.
Ensure all asynchronous operations involving Playwright objects are `await`ed. Use `with sync_playwright() as p:` for synchronous API to ensure proper resource management. Avoid closing pages, contexts, or browsers until all intended interactions with them are complete. If iterating, use `for...of` loops with `await` for asynchronous operations inside the loop.