Manuals / Playwright with Python / Ch 12

Part 2 · Core InteractionsBeginner45 min read

6. Actions

Playwright with Python · 244 pages source format

Click, fill, check, select, hover, keyboard — every action auto-waits for actionability before running.

What you'll learn

  • click / fill / type differences
  • check, select_option, hover
  • keyboard and modifier chords

Clicks and fills

click() waits until the target is actionable, then clicks the center (or a position you specify). Prefer role/name locators so you’re clicking what the user sees.

fill() clears the field and sets the value in one shot — usually what you want for forms. type() / press_sequentially() send keystrokes and are better when the app listens to individual input events.

Click and fill
page.get_by_role("button", name="Submit").click()
page.get_by_label("Email").fill("you@example.com")
Interactive study board
Clicks and fillsDrag 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 →
Clear?

Checks, selects, hover, keyboard

check() / uncheck() are for checkboxes and radios. select_option() works with <select> by value, label, or index. hover() is useful before menus that only appear on mouseover.

keyboard.press and locator.press cover shortcuts (Control+A, Enter). Prefer locator-targeted presses when focus matters.

Common actions
page.get_by_label("Remember me").check()
page.get_by_label("Country").select_option(label="Nepal")
page.get_by_role("button", name="Account").hover()
page.get_by_placeholder("Search").press("Enter")

Do this now

Automate a small form: fill, select, check, submit — all user-facing locators.

Pro tip. If click flakes because something overlays the button, fix the wait for that overlay — don’t add time.sleep.

Interactive study board
Checks, selects, hover, keyboardDrag 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 →
Clear?

Checklist