QA Interview Hub · Knowledge base · Quizzes · Українська

Playwright › Interaction: actions, tabs, frames, files, dialogs

Actions on elements: what to use when

The action method is chosen by the browser events the app listens to. Ordinary fields are filled by fill with a single input event, while pressSequentially types key by key (keydown, keypress, input, keyup) for autocomplete, masks and debounced search. check beats click because it is idempotent and verifies the final state, and force: true hides a real defect.

Playwright · Interaction

The city field is filled but no autocomplete suggestions appear. fill worked, so why is the app silent?

A test types "Lv" into the city field and waits for the suggestion list. The value is in the field, the screenshot confirms it, yet the list never shows up and the test fails on the assertion. The test is not broken: it "talks" to the page differently from a person. The input method was picked for convenience, not for the events the app is waiting for. This article is about choosing the action method: what each one really does to the page and where the difference hides.

How it works and why. Every action (click, fill, check…) has two parts. First the locator finds the element, waits for actionability (visible, stable, enabled, not covered) and scrolls it into view if needed. Then the action itself runs, and Playwright waits for any navigations it started. The methods differ in the second part: they produce different sets of browser events, and the app reacts to events, not to "the value in the field".

fill focuses the field, clears it and inserts the value in one step, sending a single input event. It is fast and independent of the keyboard layout, so fill is the standard for ordinary inputs, textarea and contenteditable. pressSequentially types character by character: every key gets the full keydown → keypress → input → keyup cycle. It is needed where the logic hangs on keys: autocomplete, phone or card masks, debounced search. The old type is deprecated and was replaced by pressSequentially.

What the app sees in an autocomplete field

Typical

fill('Lv')

The value lands in the field in one step, with a single input event. keydown and keyup handlers are not called, so autocomplete never starts.

Better

pressSequentially('Lv')

Each letter goes through the full key event cycle, like a person typing. Autocomplete, masks and debounce work as they do for a user.

Figure 1. The value in the field is the same, but the set of events differs. The app reacts to events, not to the value.

Example: autocomplete that does not "hear" fill. The city field fires a suggestions request on every key press. A test written out of habit:

// before: the field is filled, but the suggestions never appear
await page.getByLabel('City').fill('Lv');
await expect(page.getByRole('option', { name: 'Lviv' })).toBeVisible(); // timeout

The failure looks like a waiting problem, and the first reaction is usually to raise the timeout or add a pause. That will not help, because the event that starts the search never happened. The clue is that the value in the field is right while nothing reacts to it. The fix: send the keys.

// after: the app sees real key presses
await page.getByLabel('City').pressSequentially('Lv');
await page.getByRole('option', { name: 'Lviv' }).click();

// a slow mask or a field that drops fast input: add a delay per key
await page.getByLabel('Phone').pressSequentially('501234567', { delay: 50 });

// a single key or a chord
await page.getByLabel('Search').press('Enter');
await page.getByLabel('Notes').press('ControlOrMeta+A');

Why this is right and "paste the text and poke the field" is wrong: the test reproduces the user's path, and if the key handler breaks in the app, the test will show it. The delay option is rarely needed: a debounced field waits for a pause after the last key, so fast typing does not hurt it. Add a delay only when the app truly drops fast input, and only for that reason.

Choices and toggles. check and uncheck do not just click: after the click they verify that the state really changed and throw if not (for example, a handler cancelled the change). If the checkbox is already in the wanted state, the action does nothing, so the test is idempotent. setChecked(bool) is handy in parameterised tests. selectOption works only with a native select: by value, label, index, or an array for multiple. A custom dropdown is made of ordinary divs, so it is opened with a click on the combobox and the option is picked through getByRole('option'). For date and time fields fill expects the format of the input type (yyyy-mm-dd, HH:mm, yyyy-MM-ddTHH:mm), not the user's locale.

A checkbox: click or check

Typical

click()

Just presses. If the checkbox is already checked (left over from a previous scenario), the click clears it. Nobody verifies the state after the click.

Better

check()

Sets the wanted state: an already checked box is left alone. After the click it verifies the result and fails if the state did not change.

Figure 2. For checkboxes and radio buttons the method should express the intent "must be checked", not "press".
await page.getByRole('checkbox', { name: 'Accept terms' }).check();
await page.getByRole('checkbox', { name: 'Newsletter' }).setChecked(false);
await page.getByLabel('Currency').selectOption({ label: 'UAH' });
await page.getByLabel('Tags').selectOption(['qa', 'ci']); // <select multiple>

// custom dropdown built from divs: a click, not selectOption
await page.getByRole('combobox', { name: 'Country' }).click();
await page.getByRole('option', { name: 'Ukraine' }).click();

// date inputs take the format of the input type, not of the locale
await page.getByLabel('Date').fill('2026-10-08'); // type="date"
await page.getByLabel('Time').fill('14:30'); // type="time"

Mouse and drag. Every click moves the cursor to the element automatically, so a separate hover is needed only for menus that open on hover and for tooltips. click options: button, modifiers, position (a point inside the element), clickCount, delay. force: true skips the actionability checks, so it hides real problems such as overlap or a disabled element, and stays a last resort. trial: true runs all the checks but does not perform the action. dragTo is enough for most drag-and-drop, and for libraries that listen to intermediate mousemove events the drag is assembled by hand with page.mouse and the steps option.

await page.getByRole('menuitem', { name: 'Products' }).hover();
await page.getByRole('link', { name: 'Laptops' }).click();

await page.getByRole('row', { name: 'Order 42' }).click({ button: 'right' });
await page.getByRole('row', { name: 'Order 42' }).click({ modifiers: ['Shift'] });
await page.getByRole('cell', { name: 'Amount' }).dblclick();

// check that the click would be possible, without doing it
await page.getByRole('button', { name: 'Pay' }).click({ trial: true });

// drag and drop: the simple way
await page.getByTestId('card-1').dragTo(page.getByTestId('column-done'));

// the manual way, for libraries that listen to mousemove
const handle = await page.getByTestId('slider-handle').boundingBox();
if (!handle) throw new Error('handle is not visible');
await page.mouse.move(handle.x + handle.width / 2, handle.y + handle.height / 2);
await page.mouse.down();
await page.mouse.move(handle.x + 200, handle.y + handle.height / 2, { steps: 10 });
await page.mouse.up();
TaskMethodWhy
Ordinary fieldfillfast, one input event
Autocomplete, mask, debouncepressSequentiallythe app listens to every key
Enter, Tab, Ctrl+Apressone key or a chord
Checkbox, radiocheck / setCheckedverifies the final state
Native selectselectOptionby value, label or array
Custom dropdownclick + getByRole('option')they are ordinary elements
Hover menuhover + clickthe item does not appear without hover

Limits and alternatives. press with ControlOrMeta becomes Control on Windows and Linux and Meta (Cmd) on macOS, so one test works on every OS. All these methods model a user rather than push a value into the app, so if you only need to prepare state (for example, open a form with the fields already filled), it is faster to do that through the API or storageState than through the UI. In Cypress type types key by key by default, so "paste in one step" is a separate choice there; in Playwright it is the other way round: fast fill by default, and key-by-key typing has to be chosen on purpose. In Selenium sendKeys also sends keys, so the habit "always type" carries over to Playwright as pressSequentially everywhere, which brings slowness.

Common mistakes.

  • pressSequentially everywhere "just in case": tests get slower with no gain when the field does not listen to keys.
  • fill where the app listens to keys: the value is there, the suggestions or mask are not, and the test fails with a vague cause.
  • click on a checkbox instead of check: the test will not notice that the state did not change, and a rerun on an already checked box clears it.
  • force: true instead of finding out why the element is covered: the test passes while a real user could not press the button.
  • A locale-style date (08.10.2026) in fill for type="date": a format error.
  • selectOption on a custom dropdown: it has no select tag.

Check yourself

After fill('Lv') the city value is right, but the suggestion list does not appear. Will waitForTimeout(2000) before the assertion help?

Answer

No. The key event the autocomplete waits for never happened, so no matter how long the test waits, the search does not start. You need pressSequentially, which sends keydown, keypress, input and keyup, not a pause.

A checkbox stayed checked from the previous scenario. What happens after click() and what after check()?

Answer

click() clears it, because it just presses, and the test goes on with the wrong state. check() sees that the box is already checked and does nothing; otherwise, after the click, it verifies that the state became "checked".

A test with click({ force: true }) on "Pay" is green, yet users complain the button does not respond. Why, and how do you find the cause?

Answer

force skips the "receives events" check, so the click goes to the button's coordinates even though a banner or modal covers it. Remove force and read the failure log: it names the element that intercepts events. Then close it like a user would, or fix the layout.

In an interview. Junior: For ordinary fields I use fill, for a native select selectOption, for checkboxes check. I open a custom dropdown with a click and pick the option by role. Middle/Senior: I choose the method by the events the app listens to: pressSequentially only for autocomplete, masks and debounced search, because fill does not fire keydown/keyup. check beats click because it is idempotent and verifies the final state. I treat force: true as a smell: first I find what covers the element, otherwise the test goes green where a user would be stuck.

More articles in this chapter