How to Setup Playwright with Python

Profile picture for user arilio666

A few steps are involved in configuring Playwright using Python, but they are not burdensome.

1. Install Playwright

You can install Playwright for Python using pip by running the following command.

pip install pytest-playwright


2. Install a browser

Playwright is compatible with the browsers Chromium, Firefox, and WebKit. Run the following command to install any of these browsers:

python -m playwright install


3. Launch a browser instance

After installing Playwright and a browser, you can use the following code to build a new Python script and launch a browser instance.

from Playwright.sync_api import sync_playwright
with sync_playwright() as p:
   browser = p.chromium.launch(headless=False)
   page = browser.new_page()
   page.goto('https://www.programsbuzz.com')

This code will launch a Chromium browser instance and navigate to www.programsbuzz.com.