Microsoft · browser automation & testing · Chromium / Firefox / WebKit · verified against Playwright 1.61 (2026)

Playwright cheat sheet

Playwright automates real browsers (Chromium, Firefox, WebKit) with one API — for end-to-end testing, JS-rendered scraping, and RPA. Its defining features: auto-waiting (actions wait for elements to be actionable, so no manual sleeps), resilient locators (find elements the way a user would), and web-first assertions that retry. This sheet targets Playwright Python 1.61 and uses the sync API (an async twin exists). Great when requests/Scrapy can't run the page's JavaScript.

launch & navigate locators actions assertions & waiting context, network, capture gotcha most common

Verified 2026-08-24 against the official docs at playwright.dev/python (Playwright 1.61) and microsoft/playwright-python. Needs a one-time browser download (playwright install). Pairs with pytest-playwright for testing.

Outline

Locate → act → assert. The mental shift from Selenium: never sleep — Playwright auto-waits, and assertions retry.

Start

  1. 1 · Install & launch
  2. 2 · Navigate

Find

  1. 3 · Locators (get_by_*)
  2. 4 · Filter & chain

Act & verify

  1. 5 · Actions
  2. 6 · Assertions (expect)
  3. 7 · Waiting & navigation

Advanced

  1. 8 · Context, auth, network
  2. 9 · Capture & tooling
  3. 10 · Gotchas
  4. Worth memorizing

Start

Install browsers, launch, open a page.

1Install & launch1.61

Find Elements

Locators are lazy queries — resolved fresh on each action, so they don't go stale.

3Locators (get_by_*)user-facing
4Filter & chainnarrow down

Act & Verify

Interact, then assert — both auto-wait.

5Actionsauto-waiting
6Assertions (expect)web-first, retrying
7Waiting & navigationthe rare explicit wait

Advanced

Contexts for auth/isolation, network control, and capture.

8Context, auth, networkpower features
9Capture & toolingscreenshots, codegen, trace
!Common gotchasread before shipping

Worth memorizing

playwright install firstpip package needs the browser binaries downloaded
locate → act → assertget_by_role → click → expect(...).to_be_visible()
never sleepactions auto-wait; expect retries — wait for conditions, not time
get_by_role is the best locatorresilient & user-facing; get_by_test_id for your own app
expect() is web-first & retriesnot the same as assert is_visible()
strict mode = one matchrefine, or .first/.nth() on purpose
storage_state = log in oncesave auth, reuse across contexts
page.route to mock/blockstub APIs, block images to speed up
codegen & trace viewerrecord scripts; debug every step visually