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

Playwright › Auto-waiting and web-first assertions

Actionability: what exactly is checked before an action

Before click Playwright checks the element is visible, stable, enabled and not covered; before fill, only that it is visible, enabled and editable. The set of checks depends on the action. If a check fails, Playwright waits and retries until the timeout, so extra pauses are unnecessary. The cause of a timeout is in the call log, which names the failed check and the blocking element.

Playwright · Waiting

The button is on screen, yet the click fails with a timeout. Doesn't Playwright "wait by itself"?

A test clicks "Buy" and fails 30 seconds later. In the report screenshot the button is in place, not disabled, and nothing is animating. The cause is usually one thing: before a click Playwright runs a set of checks, and one of them did not pass before the time ran out. That set is called actionability. Below: how it works, why it is designed this way, and how to find the culprit from one line of the log.

How it works and why. A user does not click a button that has not been drawn yet, that is sliding across the screen, or that is covered by a banner. Playwright models this: before an action it checks that the element is in a state where a person could work with it, and if not, it waits and checks again until the timeout. Hence the main design choice: waiting is built into every action instead of being left to the test author. In Selenium you write the explicit wait (WebDriverWait) yourself, and it gets forgotten; Cypress has similar checks too (the element must be visible, not covered, not disabled), but the set and the behavior differ, so do not carry habits over.

The loop of checks before an action

1 attached 2 visible 3 stable 4 receives events 5 enabled any "no":wait andtry again all "yes" timeis out the action runs timeout:error + log
Figure 1. The checks run as a loop with only two exits: the action or the timeout. The set differs per action, and the order is approximate.

Which checks run. All actions wait for the element to be attached to the DOM, and beyond that the set depends on the action:

ActionWhat Playwright waits for
click, check, uncheck, setChecked, tapvisible, stable, receives events, enabled, not inert
hover, dragTovisible, stable, receives events
fill, clearvisible, enabled, editable, not inert
selectOptionvisible, enabled, not inert
screenshotvisible, stable
  • Visible: a non-empty bounding box and no visibility: hidden. An element with zero size or display: none is invisible, while one with opacity: 0 is considered visible.
  • Stable: the same bounding box in two consecutive animation frames. The reason: a click at a moving target lands "next to" it.
  • Receives events: at the action point there is this very element, not an overlay, modal or spinner covering it.
  • Enabled: the element is not disabled (including fieldset disabled and aria-disabled="true").
  • Editable: enabled and not readonly.
  • Not inert: the element is not inside a subtree with the inert attribute (since 1.65): a user cannot interact with such an element.

Before a click the element is also scrolled into view.

Example: the test fails and we read the log. A cookie banner has just appeared and covers the bottom part of the screen.

// before: hoping that it "will somehow pass"
await page.goto('/product/42');
await page.getByRole('button', { name: 'Buy' }).click();
Error: locator.click: Timeout 30000ms exceeded.
Call log:
  - waiting for getByRole('button', { name: 'Buy' })
  -   locator resolved to <button class="buy">Buy</button>
  - attempting click action
  -   waiting for element to be visible, enabled and stable
  -   element is visible, enabled and stable
  -   scrolling into view if needed
  -   <div class="cookie-banner">…</div> intercepts pointer events
  - retrying click action
  -   waiting 20ms

The log is shortened: the real output has more service lines (scrolling, full selectors, attempt counters), and the wording depends on the Playwright version.

How to read it. The "locator resolved to" line says the element was found, so the locator is not the problem. "visible, enabled and stable" already passed. Only the fourth check failed: "intercepts pointer events" names the obstacle. Then comes "retrying" (the loop from the figure). So in this case neither a longer pause nor another locator will help.

// after: remove the obstacle the way a user would
await page.getByRole('button', { name: 'Accept' }).click();
await page.getByRole('button', { name: 'Buy' }).click();

Two ways to "fix" a covered button

Typical

click({ force: true })

The checks are skipped and the click goes to the button's coordinates. The test is green although a user cannot press the button: the banner bug stays unnoticed.

Better

Close the overlay or wait for it to go away

The test does what a person does. If the banner can no longer be closed, the failure shows a real defect.

Figure 2. The same red test can be "fixed" in two ways, and only the second hides nothing.

force and trial. force: true skips the actionability checks: useful only for unusual elements that react to the event correctly although they are formally "covered". trial: true does the opposite: it passes all the checks but does not perform the action, so you can wait for readiness, for example before a hover menu, or verify that a button is really clickable.

await page.getByRole('menuitem', { name: 'Profile' }).hover({ trial: true });

Timeouts. How long an action waits is set by actionTimeout. It defaults to 0, meaning no separate limit, so the action waits until the timeout of the whole test (30 seconds) is used up. A single hung action eats the whole budget and the error arrives late. That is why people often set use: { actionTimeout: 10_000 } in the config: the failure is fast, and the log is the same.

Navigation. It has separate rules: page.goto waits for the load event by default, and waitUntil changes the readiness moment (domcontentloaded, commit). The networkidle option is officially discouraged: with polling, WebSockets or analytics there may be no "silence", and when there is, it is still not UI readiness. The page.waitForNavigation method is outdated. After an action that changes the URL, verify the result: await expect(page).toHaveURL(/orders/) or page.waitForURL. If you need a specific API response, create the wait before the action:

const responsePromise = page.waitForResponse(
  (res) => res.url().includes('/api/orders') && res.request().method() === 'POST',
);
await page.getByRole('button', { name: 'Place order' }).click();
const response = await responsePromise;
expect(response.status()).toBe(201);

Limits. Actionability guarantees that the element is ready for the action, not that the needed data or text has appeared in it: web-first assertions exist for that. It does not wait for a request to finish or for an element that is not in the DOM yet (the loop just keeps spinning while the locator finds nothing). And it cannot tell "the banner is still disappearing" from "the banner will never disappear": the second case remains a real defect.

Common mistakes.

  • force: true against "intercepts pointer events": the check is off, the bug is hidden, and in production the button is unreachable.
  • waitForTimeout before a click: Playwright already waits, and a pause only slows things down without guaranteeing readiness.
  • networkidle as "the page has loaded": on live pages it is unreliable.
  • No actionTimeout: a hung action eats 30 seconds and the cause gets lost in a long log.
  • Expecting actionability to wait for text or data: it checks the state of the element, not its content.

Check yourself

The log has "element is visible, enabled and stable", then right after it "intercepts pointer events" and a timeout. Will raising the timeout to 60 seconds help?

Answer

No, if the covering element does not go away by itself: the "receives events" check will never pass, and Playwright will just retry for longer. You need to find out what that element is (the log names it) and close it or wait until it disappears. A longer timeout helps only when the overlay is temporary, such as a spinner.

How does locator.fill() differ from click() in its set of checks, and why is that logical?

Answer

fill does not need stable and receives events, but it needs editable: a field can be filled without clicking a point, but not if it is readonly. The set depends on what the action itself requires.

In an interview. Junior: Before a click Playwright itself waits for the element to be visible, stable, enabled and not covered, so separate pauses are not needed. Middle/Senior: On a timeout I read the call log: it shows which check failed and which element covers the target. I almost never use force: true, because it hides a real defect (a user cannot click either), and instead of networkidle I wait for a concrete result: a URL, an element or an API response. I set actionTimeout so that failures are fast.

More articles in this chapter