Skip to content
|By Muhammad Wilayat Shah|48 views • 47 unique IPs

Playwright Timeout Error: How to Fix Locator Timeouts

Checkout tests failed one CI run in four with Test timeout of 30000ms exceeded. Here is how I read the call log to find the real cause, with real Playwright 1.65 output and fixes.

ShareLinkedInX
Four-step diagram for fixing a Playwright timeout error: identify which timeout fired, count what the locator matches, check actionability such as disabled, covered or hidden elements, then wait for responses and assertions instead of fixed sleeps
Four-step diagram for fixing a Playwright timeout error: identify which timeout fired, count what the locator matches, check actionability such as disabled, covered or hidden elements, then wait for responses and assertions instead of fixed sleeps

Last reviewed: 22 Nov 2026

Our order-management web app has about 140 Playwright tests that run on every pull request. One week the checkout tests started failing in CI roughly one run in four, always with the same line: Test timeout of 30000ms exceeded on a click. Locally they passed every time. Someone raised the timeout to 60 seconds; the tests now failed in 60 seconds instead of 30.

The trace showed the real story in under a minute. A new "saving address" overlay stayed on screen a little longer on the slower CI runners, and the click was landing on the overlay, not the button. Playwright had told us so in the call log the whole time.

That is the pattern behind almost every Playwright timeout error. Playwright is not too slow; it waited for something that was never going to happen. Below is how I find out what it was waiting for, with error output I reproduced on Playwright 1.65.1.

A one-minute diagnosis: which timeout fired?

Playwright has separate timeouts, and the first line of the error tells you which one ran out:

  • Test timeout of 30000ms exceeded is the whole test (default 30 s, including hooks and fixtures). Actions and navigations have no timeout of their own by default, so a stuck click simply runs until this one ends the test.
  • locator.click: Timeout 10000ms exceeded is an action timeout (actionTimeout, unset by default).
  • expect(locator).toBeVisible() failed ... Timeout: 5000ms is an assertion (default 5 s).
  • page.goto: Timeout 30000ms exceeded is navigation (navigationTimeout).

Then read the Call log under the error. Its last lines say what Playwright saw while it waited. I built a small checkout page with each problem and ran it with actionTimeout: 3000; these are the real messages.

Animated table mapping Playwright timeout messages to causes: call log stopping at waiting for means the locator matches nothing, strict mode violation resolved to 2 elements means scope the locator with filter, element is not enabled means wait for the enabling state, a div intercepts pointer events means wait for the loader to be hidden, expect toBeVisible element not found means check the API and app state, and Test timeout exceeded on one step means set actionTimeout
Six call-log patterns and what each one means. The answer is almost always in the last lines of the log, not in the timeout value.

Fixes by cause

1. The locator matches nothing

The call log has one line and never says "resolved to":

Code
TimeoutError: locator.click: Timeout 3000ms exceeded.
Call log:
  - waiting for getByRole('button', { name: 'Confirm order' })

The button text changed, the selector depends on a generated CSS class, or the element is inside an iframe. Check the count in a debug run:

Code
const button = page.getByRole('button', { name: 'Place order' });
console.log(await button.count());   // 0 = no match, 2+ = ambiguous

Use npx playwright codegen http://localhost:3000 or the "Pick locator" button in npx playwright test --ui to see what Playwright suggests, and prefer what the user sees over markup:

Code
// Brittle: tied to markup and generated class names
await page.locator('div.sc-1x7k2 > button:nth-child(2)').click();

// Stable
await page.getByRole('button', { name: 'Place order' }).click();
await page.getByLabel('Email').fill('[email protected]');
await page.getByTestId('checkout-submit').click();

For a payment form or any embedded widget in an iframe, go through the frame; a page locator will never find it:

Code
const card = page.frameLocator('iframe[title="Secure payment"]');
await card.getByLabel('Card number').fill('4242 4242 4242 4242');

2. The locator matches more than one element

Locators are strict. Two matches fail fast with a clear message, and Playwright even suggests scoped alternatives:

Code
Error: locator.click: Error: strict mode violation: getByRole('button', { name: 'View' }) resolved to 2 elements:
    1) <button>View</button> aka getByRole('listitem').filter({ hasText: 'Blue Area office View' }).getByRole('button')
    2) <button>View</button> aka getByRole('listitem').filter({ hasText: 'F-7 office View' }).getByRole('button')

Scope it to the right row instead of adding .first(), which clicks the wrong thing as soon as the order changes:

Code
await page
  .getByRole('listitem')
  .filter({ hasText: 'F-7 office' })
  .getByRole('button', { name: 'View' })
  .click();

A related trap: a hidden duplicate (a mobile menu, a closed dialog) that matches a CSS selector first. With waitForSelector the default state is visible, so it waits for the hidden one forever.

3. The element is there but disabled

Code
TimeoutError: locator.click: Timeout 3000ms exceeded.
Call log:
  - waiting for getByRole('button', { name: 'Place order' })
    - locator resolved to <button disabled id="place">Place order</button>
  - attempting click action
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action

"Resolved to" means the locator is fine. The button is disabled because a required field is empty, validation failed, or a request has not finished. Do what enables it, and assert that it happened:

Code
await page.getByLabel('Phone').fill('0300 1234567');
await expect(page.getByRole('button', { name: 'Place order' })).toBeEnabled();
await page.getByRole('button', { name: 'Place order' }).click();

4. Something is covering the element (our CI bug)

Code
TimeoutError: locator.click: Timeout 3000ms exceeded.
Call log:
  - waiting for getByRole('button', { name: 'Save address' })
    - locator resolved to <button id="save">Save address</button>
  - attempting click action
    2 × waiting for element to be visible, enabled and stable
      - element is visible, enabled and stable
      - scrolling into view if needed
      - done scrolling
      - <div class="loader" data-testid="page-loader"></div> intercepts pointer events
    - retrying click action

A loading overlay, cookie banner, toast or modal is on top. Wait for it to go away, as a user would:

Code
await expect(page.getByTestId('page-loader')).toBeHidden();
await page.getByRole('button', { name: 'Save address' }).click();

Do not use click({ force: true }). It skips the actionability checks, so the test passes while a real user still cannot click the button. Dismiss cookie banners once in a setup step or with saved storage state.

Animated terminal session with Playwright 1.65.1: locator.click on the Save address button times out after 3000ms because a div with data-testid page-loader intercepts pointer events, the test is changed to expect the loader to be hidden and to scope the View button to the F-7 office list item, and npx playwright test with repeat-each 5 shows 5 passed
The CI bug from the story, reproduced: the call log names the overlay, the fix waits for it, and five repeated runs prove it holds.

5. The app is not in the state the test expects

Code
Error: expect(locator).toBeVisible() failed

Locator: getByText('Order confirmed')
Expected: visible
Timeout: 2000ms
Error: element(s) not found

Often the UI is fine and the backend failed: a 401 because the test user's session expired, a 500, or a CORS error. Wait for the response that drives the UI and check it, instead of sleeping:

Code
// Bad: guesses how long the API takes
await page.waitForTimeout(3000);

// Good: wait for the request that matters, then for what the user sees
const saved = page.waitForResponse(
  (res) => res.url().includes('/api/orders') && res.request().method() === 'POST'
);
await page.getByRole('button', { name: 'Place order' }).click();
expect((await saved).status()).toBe(201);
await expect(page.getByText('Order confirmed')).toBeVisible();

If that status is not what you expect, you have found a real bug. For browser-to-API failures in a React and Laravel stack, see fixing CORS errors between React and Laravel. In Next.js, a click before hydration can do nothing; assert on something that only appears once the page is interactive. Pages that crash during server rendering show up here too, as in Next.js window is not defined.

6. The environment is slower or different

A cold next dev compile, a CI runner with two CPUs and four workers, or a third-party script that blocks the load event. Run tests against a production build, cap workers in CI, and set timeouts once in config, so failures name the step that got stuck:

Code
// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  timeout: 30_000,                 // whole test
  expect: { timeout: 5_000 },      // each web-first assertion
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 2 : undefined,
  use: {
    baseURL: 'http://localhost:3000',
    actionTimeout: 10_000,         // each click, fill, etc.
    navigationTimeout: 15_000,     // goto, waitForURL
    trace: 'on-first-retry',
  },
  webServer: {
    command: 'npm run build && npm run start',
    url: 'http://localhost:3000',
    reuseExistingServer: !process.env.CI,
    timeout: 120_000,
  },
});

Without actionTimeout, I reproduced exactly the confusing message from our CI: Error: locator.click: Test timeout of 4000ms exceeded. with the click as the only clue. For a test that is genuinely long, such as a full import flow, use test.slow() (triples its timeout) or test.setTimeout(60_000) inside that test only.

Get a trace before you guess

Code
npx playwright test tests/checkout.spec.ts --trace on
npx playwright show-report                # click the trace of the failed test
npx playwright show-trace test-results/<test-folder>/trace.zip

The trace has a DOM snapshot before and after every action, plus network and console logs. Select the failing step and look at the page: you usually see the overlay, the error toast or the login page straight away. In CI, trace: 'on-first-retry' gives you one for every flaky failure without slowing normal runs. If the pipeline itself is failing around the tests, my checklist for a GitHub Actions workflow that failed covers that side.

Verify the fix

Code
$ npx playwright test tests/checkout.spec.ts --repeat-each=5
  5 passed (3.0s)
$ npx playwright test --workers=4 --repeat-each=5   # closer to a busy CI runner
$ npx playwright test --fail-on-flaky-tests         # fail if a test only passed on retry

One green run proves little for a flaky test. Then break the feature on purpose (rename the button) and check that the test fails with a clear message.

Common mistakes

  • Raising timeouts first. A step that normally takes one second and sometimes takes thirty has a cause; a longer timeout just makes the failure slower.
  • page.waitForTimeout() as a fix. Slow when the app is fast, still flaky when it is slow.
  • force: true to get past an overlay. It hides a bug users can hit.
  • .first() to silence a strict mode violation.
  • Waiting for networkidle. Playwright's docs discourage it; wait for the specific response or UI state.
  • Reading values once with isVisible() or textContent() instead of retrying web-first assertions like await expect(locator).toBeVisible().
  • Tests that depend on data created by an earlier test, which breaks as soon as workers run them in a different order.

Questions I get asked

Why does Playwright say "waiting for" when I can see the element?

The element you see is not the one your locator describes: different text or spacing, inside an iframe, or a hidden duplicate that matches first. The trace's DOM snapshot shows exactly what was there.

Should I just increase the Playwright timeout?

Only when the slowness is expected, such as a large upload. Otherwise fix the locator or wait for the right state.

What is the difference between actionTimeout and the test timeout?

The test timeout limits the whole test (default 30 s). actionTimeout limits each click, fill and similar action and is unset by default. Setting it makes the error name the stuck step.

Why do Playwright tests time out only in CI?

Fewer CPUs, more parallel workers, a cold server and different data. Check the CI trace, reduce workers to see if resource pressure is the cause, and test against a production build.


About the author. Muhammad Wilayat Shah is a senior full-stack engineer and team lead based in Islamabad, with 13+ years shipping ERP, SaaS and property-portal products on Laravel, PHP, React, Next.js and PostgreSQL. He wrote this after a loading overlay made a checkout suite fail one CI run in four. More at wilayats.com/about.

Last reviewed: 22 Nov 2026

ShareLinkedInX
Back to blog

Keep reading

Fix Nginx 413 Request Entity Too Large Error

11/25/2026

Fix Nginx 413 Request Entity Too Large Error

Nginx 413 Request Entity Too Large means a body size limit was hit. Find which layer sent it, then fix client_max_body_size, PHP upload limits, Express and Kubernetes ingress.

Newsletter

Occasional notes on Laravel, React, and shipping production systems — no spam.

Comments

Join the discussion. Replies load on demand, up to 5 levels.

0 threads

Loading editor…
Reviewed before publishing

No comments yet

Be the first to start the conversation.