Selenium has long been the de facto standard for open-source Python browser automation tools, but Microsoft's open-source Playwright has gained massive traction in recent years, presenting a serious challenge to Selenium's long-held dominance. We'll break down core differences between the two frameworks here, focusing first on Playwright's setup and basic implementation.
Playwright is a Microsoft-backed end-to-end web testing and automation library with native support for all major browser engines. While its primary intended use case is automated web application testing, its headless browser functionality is also heavily utilized for web scraping workflows, thanks to built-in anti-detection features that enable stealth operation.
For Python 3.10 environments, first install the Playwright package via pip:
pip install playwright
A successful installation will return output similar to the following:
Successfully built greenlet
Installing collected packages: pyee, greenlet, playwright
Attempting uninstall: greenlet
Found existing installation: greenlet 2.0.2
Uninstalling greenlet-2.0.2:
Successfully uninstalled greenlet-2.0.2
Successfully installed greenlet-2.0.1 playwright-1.30.0 pyee-9.0.4
As of writing, the latest stable Playwright release is version 1.30.0.
Next, run the built-in driver installation command to fetch preconfigured, compatibility-validated browser binaries:
playwright install
This command automatically downloads Chromium, Firefox, and WebKit drivers, along with supporting utilities like FFMPEG:
Downloading Chromium 110.0.5481.38 (playwright build v1045) from https://playwright.azureedge.net/builds/chromium/1045/chromium-mac-arm64.zip
123.8 Mb [====================] 100% 0.0s
Chromium 110.0.5481.38 (playwright build v1045) downloaded to ~/Library/Caches/ms-playwright/chromium-1045
Downloading FFMPEG playwright build v1008 from https://playwright.azureedge.net/builds/ffmpeg/1008/ffmpeg-mac-arm64.zip
1 Mb [====================] 100% 0.0s
FFMPEG playwright build v1008 downloaded to ~/Library/Caches/ms-playwright/ffmpeg-1008
Downloading Firefox 108.0.2 (playwright build v1372) from https://playwright.azureedge.net/builds/firefox/1372/firefox-mac-11-arm64.zip
69.8 Mb [====================] 100% 0.0s
Firefox 108.0.2 (playwright build v1372) downloaded to ~/Library/Caches/ms-playwright/firefox-1372
Downloading Webkit 16.4 (playwright build v1767) from https://playwright.azureedge.net/builds/webkit/1767/webkit-mac-12-arm64.zip
56.9 Mb [====================] 100% 0.0s
Webkit 16.4 (playwright build v1372) downloaded to ~/Library/Caches/ms-playwright/webkit-1767
The Chromium engine is the most widely used of the three, powering popular consumer browsers including Google Chrome and Microsoft Edge.
If you have Microsoft Edge installed on your system, you can test a basic automation workflow with the following implementation:
from playwright.sync_api import sync_playwright
with sync_playwright() as pw_instance:
edge_browser = pw_instance.chromium.launch(channel="msedge", headless=True)
test_tab = edge_browser.new_page()
test_tab.goto("https://example.com")
test_tab.wait_for_load_state("networkidle")
test_tab.screenshot(path="./edge_test_capture.png", full_page=True)
edge_browser.close()
This code uses Playwright's synchronous execution API, with a context manager that handles browser process lifecycle management automatically. The channel parameter explicitly targets the locally installed Microsoft Edge browser, while the headless=True flag runs the browser process entirely in the background with no visible user interface. The wait_for_load_state call pauses execution untill all network activity on the page has ceased, ensuring all content is fully rendered before the screenshot is captured.