User Interactions
Click, type, select options, drag, and upload files with Playwright actions.
Click and Hover
click supports button, clickCount, modifiers (Shift, Meta). dblclick and hover simulate pointer events. force: true skips actionability checks—use rarely.
Playwright scrolls element into view before click. trial: true checks actionability without performing action.
await page.getByRole("button", { name: "Save" }).click();
await page.getByText("Menu").hover();Keyboard Input
fill clears and types text—fast for form fields. pressSequentially simulates per-key delay for autocomplete triggers. press sends single key like Enter, Tab, ArrowDown.
Clear with fill("") before typing new value. focus() then keyboard.type for low-level sequences.
- Use press for keyboard shortcuts Ctrl+S with modifiers object
- contenteditable elements may need click before fill
- Input type=file requires setInputFiles not fill
await page.getByLabel("Search").fill("playwright");
await page.getByLabel("Search").press("Enter");Select and Check
selectOption on select elements by label, value, or index. check and uncheck for checkbox; setChecked for explicit state.
Custom select components mimicking dropdowns need getByRole("option") clicks not selectOption.
await page.getByLabel("Country").selectOption("US");
await page.getByRole("checkbox", { name: "Agree" }).check();File Upload
setInputFiles on input[type=file] accepts path or buffer. Multiple files pass array. input element can be hidden—Playwright still sets files if attached to DOM.
Download flow uses page.waitForEvent("download") and saveAs.
await page.getByLabel("Upload resume").setInputFiles("fixtures/resume.pdf");
const downloadPromise = page.waitForEvent("download");
await page.getByText("Export CSV").click();
const download = await downloadPromise;
await download.saveAs("out/data.csv");Drag and Touch
dragTo moves element to target. locator.dispatchEvent for custom pointer events when library requires specific sequence.
Has touch option in config enables mobile tap; projects with device descriptors emulate iPhone viewport and userAgent.
await page.locator("#source").dragTo(page.locator("#target"));