BASICS
Launch a Browser and Navigate to a Page
Explore the concepts and examples below to master this topic.
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("https://pynfinity.com")
print(page.title())
browser.close()
Click a Button and Enter Text
Explore the concepts and examples below to master this topic.
page.fill("#username", "santosh")
page.click("#submit")
INTERMEDIATE
Take a Screenshot of a Web Page
Explore the concepts and examples below to master this topic.
page.screenshot(path="screenshot.png")
Handle Alerts and Pop-ups
Explore the concepts and examples below to master this topic.
page.on("dialog", lambda dialog: dialog.accept())
ADVANCED
Run Playwright Tests in Headless Mode
Explore the concepts and examples below to master this topic.
browser = p.chromium.launch(headless=True)
Execute Tests in Parallel with Pytest
Explore the concepts and examples below to master this topic.
pytest --numprocesses=2
Use the reference cards below for fast lookup. Perfect for brushing up on syntax while you cook your code. ๐ณ
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("https://pynfinity.com")
print(page.title())
browser.close()
page.fill("#username", "santosh")
page.click("#submit")
page.screenshot(path="screenshot.png")
page.on("dialog", lambda dialog: dialog.accept())
browser = p.chromium.launch(headless=True)
pytest --numprocesses=2
Recipe Complete! ๐
You've explored the full Playwright recipe.
Keep practising โ a language a day keeps AI away! ๐ค