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