Playwright + JS · Lesson 18 of 35

0/35 done

Module 18: Actions

18. Simulating Real User Interactions & Hardware Events

16 minlesson

Try it yourself

Implement validateFormSubmission:

  1. Accept formData containing email (string) and agreed (boolean).
  2. Return true if email contains '@' and agreed is true.

The editor has a worked example. Read it, tweak it, then press Mark as complete.

Core Actions API

javascript
// Inputs & Forms:
await page.getByLabel("Email").fill("qa@targetqa.com");
await page.getByLabel("Agree to Terms").check();
await page.getByLabel("Country").selectOption("CA");

// Gestures & Drag and drop:
await page.getByTestId("profile-avatar").hover();
await page.locator("#drag-source").dragTo(page.locator("#drop-target"));

// File upload:
await page.getByLabel("Upload Profile Picture").setInputFiles("test-data/avatar.png");

Key Takeaways & Walkthrough Summary

Playwright actions simulate real hardware-level user input. Before executing any click or keypress, Playwright automatically checks that the target element is visible, stable, enabled, and ready to receive events. Let's master user actions!

Part of the Playwright + JS course (Playwright with JavaScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.

Common Doubts & Lesson Q&A

Why does fill() not trigger keyboard listeners?

fill() sets the input value directly and dispatches input/change events. If you specifically need keydown/keyup events, use pressSequentially().

Finished reading?

Review the worked example in the editor, then mark the lesson complete.

JavaScript
Skip