Playwright + TS · Lesson 18 of 36
Module 18: Actions
Try it yourself
Implement validateRegistrationPayload:
The editor has a worked example. Read it, tweak it, then press Mark as complete.
// Text Inputs:
// fill() clears existing text and types the new text instantly
await page.getByLabel("Email").fill("qa@targetqa.com");
// press() fires keyboard keys (Enter, ArrowDown, Backspace)
await page.getByLabel("Search").press("Enter");
// Checkboxes and Radio buttons:
await page.getByLabel("Subscribe to newsletter").check();
await page.getByLabel("Dark theme").uncheck();
// Select Dropdowns:
await page.getByLabel("Country").selectOption("CA"); // by value
await page.getByLabel("Country").selectOption({ label: "Canada" }); // by visible label
// Mouse gestures:
await page.getByRole("button", { name: "Save" }).click({ button: "right" }); // right-click
await page.getByTestId("menu-item").hover(); // hover to reveal dropdown
await page.locator("#source-card").dragTo(page.locator("#target-column"));fill() vs pressSequentially()fill(): Sets the input value directly (ideal for fast form completion).pressSequentially(): Types character by character with configurable delays (ideal for testing real-time search autosuggest or masked credit card inputs).await page.getByPlaceholder("Search products").pressSequentially("Laptop", { delay: 100 });// Upload file
await page.getByLabel("Upload Profile Picture").setInputFiles("test-data/avatar.png");
// Download file
const downloadPromise = page.waitForEvent("download");
await page.getByRole("button", { name: "Export CSV" }).click();
const download = await downloadPromise;
await download.saveAs("/tmp/export.csv");Playwright actions simulate authentic user interactions. Before clicking or typing, Playwright automatically checks that the target element is visible, stable, enabled, and ready to receive events. In this lesson, we will master click, fill, check, selectOption, drag and drop, and file uploads. Let's get hands-on!
Part of the Playwright + TS course (Playwright with TypeScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
fill() dispatches standard input and change events. If a reactive UI specifically relies on keydown/keyup events, use pressSequentially() instead.
Yes! Using page.mouse.down() and page.mouse.move() or locator.dragTo() allows smooth drag interactions.
Finished reading?
Review the worked example in the editor, then mark the lesson complete.