Course contentsShow
← React
Lesson 2166 of 2,39648. End-to-End TestingFree lesson

Testing User Interactions: Clicks, Fills, Selects

Simulate real user actions with page.click(), page.fill(), page.selectOption(), and keyboard/mouse events.

Testing User Interactions: Clicks, Fills, Selects

What you'll learn: How to simulate real user actions like clicking buttons, typing text, and selecting options using Playwright's interaction methods.

The Core Interaction API

Playwright provides intuitive methods that mirror actual user behavior. When a user interacts with your app, they click elements, fill in forms, and select from dropdowns. Playwright replicates these actions programmatically.

page.click() simulates clicking on an element:

await page.click('button:has-text("Submit")');
await page.click('[data-testid="login-button"]');

page.fill() types text into input fields, automatically clearing existing content first:

await page.fill('input[name="email"]', 'user@example.com');
await page.fill('#password', 'secret123');

page.selectOption() chooses options from <select> dropdowns:

await page.selectOption('select#country', 'US');
await page.selectOption('select#role', { label: 'Administrator' });

Beyond Basic Interactions

For more complex scenarios, Playwright provides keyboard and mouse events:

// Keyboard shortcuts
await page.keyboard.press('Enter');
await page.keyboard.press('Control+A');

// Mouse actions
await page.hover('.tooltip-trigger');
await page.dblclick('.editable-field');

Think Like a User

These methods are designed around real user behavior. You're not manipulating the DOM directly—you're instructing Playwright to interact as a person would. Combined with auto-waiting (from the previous lesson), these actions wait for elements to be ready before interacting, just like a human would naturally wait for a button to appear before clicking it.

Key Takeaway: Playwright's click(), fill(), selectOption(), and keyboard/mouse methods simulate authentic user interactions, automatically handling timing and actionability to create reliable end-to-end tests that mirror real usage patterns.