Interaction
Commands
| Command | Description |
|---|---|
click <ref> [button] | Click an element (left, right, or middle button) |
dblclick <ref> [button] | Double-click an element |
fill <ref> <text> | Clear and fill text into an input |
fill <ref> <text> --submit | Fill and press Enter |
type <text> | Type text into the focused element |
select <ref> <value> | Select a dropdown option |
check <ref> | Check a checkbox or radio button |
uncheck <ref> | Uncheck a checkbox |
hover <ref> | Hover over an element |
drag <startRef> <endRef> | Drag and drop |
upload <file> | Upload files |
resize <width> <height> | Resize the browser window |
Targeting elements
Refs from snapshots (recommended)
playwright-cli snapshot # get element refs
playwright-cli click e15 # click by ref
playwright-cli fill e3 "hello" # fill by ref
CSS selectors
playwright-cli click "#main > button.submit"
playwright-cli click "[data-testid='submit']"
playwright-cli fill "#email" "test@example.com"
Playwright locators
playwright-cli click "getByRole('button', { name: 'Submit' })"
playwright-cli click "getByTestId('submit-button')"
playwright-cli click "getByText('Login')"
playwright-cli fill "getByLabel('Email')" "test@example.com"
Form interaction
# Fill a text field
playwright-cli fill e3 "test@example.com"
# Fill and submit (presses Enter)
playwright-cli fill e3 "search query" --submit
# Select from dropdown
playwright-cli select e7 "United States"
# Checkboxes
playwright-cli check e10 # check
playwright-cli uncheck e10 # uncheck
# File upload
playwright-cli upload /path/to/file.pdf
# Resize browser window
playwright-cli resize 375 812 # mobile viewport
playwright-cli resize 1920 1080 # desktop
Workflow: login form
$ playwright-cli snapshot
# - textbox "Email" [ref=e3]
# - textbox "Password" [ref=e5]
# - checkbox "Remember me" [ref=e7]
# - button "Sign in" [ref=e9]
$ playwright-cli fill e3 "alice@example.com"
$ playwright-cli fill e5 "s3cureP@ss!"
$ playwright-cli check e7
$ playwright-cli click e9
$ playwright-cli snapshot
# - heading "Welcome back, Alice!" [level=1]