PLAYWRIGHT UIINTERMEDIATE

Playwright Actions: Complete Guide to Click, Fill, Hover, Keyboard, Mouse & File Upload

Master every Playwright action with practical examples including click(), fill(), hover(), dblclick(), dragAndDrop(), keyboard, mouse, file upload, and enterprise best practices.

iff Solution Academy July 8, 2026 20 min read Updated July 2026
Playwright Actions Click Fill Hover Keyboard Mouse File Upload Drag and Drop

What are Playwright Actions?

Playwright actions simulate real user interactions with a web application.

Every action automatically waits until the target element is ready before execution, making Playwright tests significantly more stable than traditional automation frameworks.

click()

Click is the most commonly used action.

ts
await page.getByRole('button', {
    name: 'Login'
}).click();

Playwright automatically waits until the button is visible, enabled, and ready.

Double Click

ts
await page.locator('.product')
    .dblclick();

Useful for desktop-style web applications.

Right Click

ts
await page.locator('.menu')
    .click({
        button: 'right'
    });

Perfect for testing context menus.

dblclick()

Performs two rapid clicks on the target element.

ts
await page.locator('.file').dblclick();

Use dblclick() when the application behavior depends on a double-click event.

check() & uncheck()

ts
await page.getByRole('checkbox')
    .check();
ts
await page.getByRole('checkbox')
    .uncheck();

Works for both checkboxes and radio buttons.

fill()

ts
await page.getByLabel('Email')
    .fill('admin@test.com');

fill() automatically clears the existing value before entering new text.

clear()

ts
await page.locator('#username')
    .clear();

Removes existing input.

press()

ts
await page.getByLabel('Search')
    .press('Enter');

Common keys include:

  • Enter
  • Escape
  • Tab
  • ArrowDown
  • ArrowUp
  • Backspace

selectOption()

ts
await page.locator('#country')
    .selectOption('USA');

You can also select by:

  • value
  • label
  • index

hover()

ts
await page.getByRole('button', {
    name: 'Products'
}).hover();

Useful for dropdown menus and tooltips.

dragAndDrop()

ts
await page.dragAndDrop(
    '#source',
    '#target'
);

Ideal for Kanban boards and drag-and-drop interfaces.

File Upload

ts
await page
    .locator('input[type=file]')
    .setInputFiles('resume.pdf');

Upload multiple files:

ts
await page
    .locator('input[type=file]')
    .setInputFiles([
        'resume.pdf',
        'image.png'
    ]);

Keyboard Actions

ts
await page.keyboard.type('Playwright');

Keyboard shortcut:

ts
await page.keyboard.press('Control+A');

await page.keyboard.press('Delete');

Mouse Actions

ts
await page.mouse.move(300, 200);

await page.mouse.down();

await page.mouse.up();

Useful for drawing applications and canvas testing.

Scroll

ts
await page.mouse.wheel(0, 500);

Or scroll a specific element into view:

ts
await page.locator('.footer')
    .scrollIntoViewIfNeeded();

Enterprise Best Practices

  • Prefer semantic locators.
  • Never use coordinates unless necessary.
  • Avoid force clicking.
  • Trust Playwright Auto Waiting.
  • Build reusable Page Object methods.
  • Use descriptive method names.

Common Mistakes

Avoid raw CSS selectors:

ts
await page.click('#login');

Prefer semantic locators:

ts
await page.getByRole('button', {
    name: 'Login'
}).click();

Avoid hard waits:

ts
await page.waitForTimeout(5000);

Playwright already waits automatically.

Interview Questions

Difference between click() and dblclick()?

click() performs a single click. dblclick() performs two rapid clicks.

Why use fill() instead of type()?

fill() clears the field before entering text and is generally faster and simpler for standard input scenarios.

When should dragAndDrop() be used?

Whenever the application supports drag-and-drop interactions such as Kanban boards, dashboards, file organization, or workflow builders.

Summary

Playwright provides one of the richest action APIs available in modern test automation.

By combining automatic waiting with expressive action methods, Playwright enables engineers to build readable, maintainable, and highly reliable UI automation frameworks.

Mastering these actions is essential for becoming a professional Playwright automation engineer.

Get Playwright tutorials in your inbox

Weekly tips, real-world examples, and framework patterns – no spam, unsubscribe anytime.

Recommended Next Articles