Manuals / Playwright with Python / Chapter 9

Part 1 · Foundations · beginner · ~50 min · Chapter 9 of 61

4. First Script

Launching a browser (headless vs headed) from playwright.sync_api import sync_playwright with sync_playwright() as p: browser = p.chromium.launch(headless=False) # headed — visible window headless=True (the default) runs with no visible window — faster and what CI environments require. headless=False opens an actual visible browser window — invaluable while you're first writing a test and want to

Path progress
13%

Step 1 of 5

Launching a browser (headless vs headed)

browser = p.chromium.launch(headless=False) # headed — visible window headless=True (the default) runs with no visible window — faster and what CI environments require. headless=False opens an actual visible browser window — invaluable while you're first writing a test and want to watch what's happening. A common workflow: write and debug with headless=False, then flip to True (or just remove the argument) once the test is stable and you're ready to commit it.

Launching a browser (headless vs headed)Drag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Page under testdrag · tap →Multi-browserdrag · tap →Automation pathdrag · tap →Tooling nodedrag · tap →

Try it

Run / study this snippet

from playwright.sync_api import sync_playwright
Was this step clear?
Chapter learning outcomes
  • Launching a browser (headless vs headed)
  • Navigating to a URL
  • Closing browser/context properly

Clear these before you leave

Side quest

4. First Script deliverable

Apply one idea from “Launching a browser (headless vs headed)” in a small script or note.