Playwright Timeout Error: Causes and Solutions


 A timeout is one of the most common problems beginners face when learning Playwright.

You may see an error such as:

TimeoutError: locator.click: Timeout 30000ms exceeded


or:

Timeout of 30000ms exceeded.


It is tempting to solve the problem by changing 30_000 to 60_000 or adding:

await page.waitForTimeout(5000);


But that does not necessarily fix the real problem.

The important question is not simply "How can I make Playwright wait longer?"

It is:

"What was Playwright waiting for, and why did that condition never happen?"

Playwright already performs automatic waiting for many actions and web assertions. For example, before clicking a locator, Playwright checks conditions such as visibility, stability, whether the element receives events, and whether it is enabled.

That means a timeout often provides useful information about your application or test.


What Is a Playwright Timeout Error?

A Playwright timeout error occurs when an operation does not finish before its configured timeout.

Different operations can have different timeout settings.

Timeout

What it controls

Test timeout

Maximum time available for a test

Action timeout

Maximum time for actions such as click/fill

Navigation timeout

Maximum time for navigation

Assertion timeout

Maximum time for auto-retrying assertions

Fixture timeout

Maximum time available for certain fixtures

Playwright Test currently uses a default test timeout of 30 seconds and a default assertion timeout of 5 seconds. Action and navigation timeouts can also be configured separately.

Understanding which timeout failed is the first step toward fixing the problem.


1. Test Timeout

Consider:

import { test, expect } from '@playwright/test';


test('dashboard test', async ({ page }) => {

  await page.goto('/dashboard');


  await expect(page.getByText('Dashboard')).toBeVisible();

});


If the complete test, including fixture setup and relevant hooks, takes longer than the configured test timeout, the test can fail.

A test timeout is different from the timeout of one individual locator operation.

For a genuinely slow end-to-end scenario, you can increase the test timeout:

test('slow report generation', async ({ page }) => {

  test.setTimeout(60_000);


  // Test steps...

});


Use this when the business operation genuinely requires more time.

Do not use it to hide a broken locator.


2. Action Timeout

Suppose you have:

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


Playwright does not immediately click the button.

It waits for the locator to resolve correctly and for the required actionability conditions to be satisfied.

A click can wait for the element to become:

  • Visible

  • Stable

  • Able to receive pointer events

  • Enabled

If these conditions never become true, the action eventually times out.

For example, this can happen when:

<button disabled>Login</button>


Your test may be correct to wait for the button if the application is expected to enable it after validation.

But if the button is permanently disabled because your test data is invalid, increasing the timeout is the wrong solution.


3. Assertion Timeout

Playwright's web-first assertions automatically retry until the expected condition is met or the assertion timeout is reached.

For example:

await expect(page.getByText('Dashboard')).toBeVisible();


This is better than manually checking the element once.

If the dashboard appears after an API request completes, the assertion can wait for the expected state.

If necessary, you can give one assertion more time:

await expect(page.getByText('Report generated'))

  .toBeVisible({ timeout: 10_000 });


This is reasonable when the operation is legitimately slower.


4. Navigation Timeout

Navigation can also time out:

await page.goto('https://example.com/dashboard');


Possible causes include:

  • Slow server response

  • DNS problems

  • Network problems

  • Redirect loops

  • Third-party resources

  • Application errors

  • Incorrect URL

  • Very slow test environment

You can configure navigation timeout:

import { defineConfig } from '@playwright/test';


export default defineConfig({

  use: {

    navigationTimeout: 30_000,

  },

});


But first determine whether the page is actually slow or the URL is wrong.


Locator Problems Are a Major Cause of Timeouts

One of the most common reasons for a Playwright timeout is an incorrect locator.

For example:

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


If the real button says:

Save Changes


Playwright may continue waiting because the expected element never appears.

Instead of increasing the timeout, inspect the page and use a locator that represents the actual UI.

For complex tests, learning how to create reliable Playwright Locators is an important part of preventing timeout failures.

Prefer user-facing locators such as:

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

page.getByLabel('Email');

page.getByText('Dashboard');


Use CSS or XPath only when they genuinely provide a better locator.


Element Exists but Is Not Visible

Another common situation is:

<button style="display:none">Submit</button>


The element exists in the DOM, but it is not visible.

This can cause:

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


to wait until the timeout.

The real fix might be:

  1. Open the correct modal.

  2. Select the correct tab.

  3. Complete required fields.

  4. Wait for the application state that makes the button visible.

For example:

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


await expect(

  page.getByRole('button', { name: 'Submit' })

).toBeVisible();


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


The test now describes the actual user flow.


Element Is Visible but Disabled

Consider:

await page.getByRole('button', { name: 'Create Account' }).click();


If the button is visible but disabled, Playwright will not simply click it.

You might need to fill required fields first:

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

await page.getByLabel('Password').fill('Password123!');


await expect(

  page.getByRole('button', { name: 'Create Account' })

).toBeEnabled();


await page.getByRole('button', { name: 'Create Account' }).click();


This is a root-cause solution.


Slow Network or API Response

Modern applications frequently depend on APIs.

For example:

Click Search

     ↓

Frontend sends API request

     ↓

Server processes request

     ↓

Response arrives

     ↓

UI displays results


If the server takes longer than usual, the UI may not immediately display the result.

Instead of:

await page.waitForTimeout(5000);

await expect(page.getByText('Results')).toBeVisible();


prefer waiting for the actual application condition:

await expect(page.getByText('Results')).toBeVisible({

  timeout: 10_000

});


For API-focused scenarios, Playwright's API testing capabilities can also help you separate backend behavior from UI behavior.


Auto-Waiting: Do You Really Need a Manual Wait?

Usually, no.

This:

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


already benefits from Playwright's actionability waiting.

This:

await expect(page.getByText('Dashboard')).toBeVisible();


uses an auto-retrying assertion.

By contrast:

await page.waitForTimeout(5000);


simply pauses the test for five seconds.

The application might be ready after one second, meaning you wasted four seconds.

Or the application might still need seven seconds, meaning the test still fails.

Playwright explicitly discourages fixed time waits in production tests because timer-based tests can become flaky.

Use conditions rather than arbitrary delays.


When Increasing a Timeout Is Appropriate

Increasing a timeout is not always wrong.

It can be appropriate when the expected operation is genuinely slow.

Examples:

  • Large file upload

  • Slow report generation

  • External service response

  • Deliberately slow staging environment

  • Complex authentication flow

  • Long-running business operation

For example:

await expect(page.getByText('Report ready'))

  .toBeVisible({ timeout: 30_000 });


The important part is that you understand why 30 seconds may be necessary.


When Increasing a Timeout Is the Wrong Solution

Do not immediately increase the timeout when:

  • The locator is wrong.

  • The URL is incorrect.

  • The element is permanently disabled.

  • A modal was never opened.

  • Required data was not entered.

  • The application is returning an error.

  • A request is failing.

  • The test is using a fixed sleep instead of a condition.

  • The test is waiting for the wrong UI state.

A 120-second timeout does not fix a button that will never appear.

It only makes the failure take longer.


A Practical Debugging Process

When a timeout occurs, follow this order.

Step 1: Read the failing operation

Find out whether the failure is:

locator.click

locator.fill

page.goto

expect(...)

test timeout

fixture timeout


Step 2: Read the locator

Ask:

Does this locator actually match the intended element?

Step 3: Check the UI state

Is the element:

  • Present?

  • Visible?

  • Enabled?

  • Stable?

  • Covered by another element?

Step 4: Check network behavior

If the UI depends on an API, determine whether the request is slow or failing.

Step 5: Check test data

Sometimes the test is waiting for an element that only appears after valid data is supplied.

Step 6: Use Playwright debugging tools

Run tests in headed/debug mode and inspect the failing step.

A dedicated Playwright debugging resource can help you investigate these failures systematically.

Step 7: Increase timeout only when justified

Once you understand the reason for the delay, configure an appropriate timeout.


A Useful Timeout Configuration

For example:

import { defineConfig } from '@playwright/test';


export default defineConfig({

  timeout: 30_000,


  expect: {

    timeout: 5_000,

  },


  use: {

    actionTimeout: 10_000,

    navigationTimeout: 30_000,

  },

});


The exact values should depend on your application rather than being copied blindly.


Timeout Error Troubleshooting Checklist

When you see a Playwright timeout error, ask:

  • Is the locator correct?

  • Is the element visible?

  • Is the element enabled?

  • Is another element covering it?

  • Is the page on the expected URL?

  • Is the API request successful?

  • Is the application still loading?

  • Did the previous action actually complete?

  • Am I using a fixed waitForTimeout()?

  • Is the test data valid?

  • Is the timeout type appropriate?

  • Does the operation genuinely need more time?

This checklist often reveals the root cause faster than simply increasing the timeout.


Frequently Asked Questions

What causes a Playwright timeout error?

Common causes include incorrect locators, invisible or disabled elements, slow navigation, API delays, incorrect test data, failed application state changes, and timeout configuration that is too short for a legitimate operation.

Why does Playwright wait for a button?

Playwright performs actionability checks before actions such as clicking. It waits for conditions such as visibility, stability, receiving events, and enabled state before performing the action.

Is page.waitForTimeout() recommended?

No. Playwright recommends condition-based waiting instead of fixed delays in production tests. Fixed waits can make tests slower and flaky.

Should I increase the Playwright timeout?

Only when the operation is legitimately slow. First check the locator, application state, network request, and test data.

What is the difference between test timeout and assertion timeout?

Test timeout limits the overall test execution, while assertion timeout controls how long an auto-retrying assertion waits for its expected condition.

How do I debug a Playwright timeout?

Start by reading the failing operation and locator, then inspect the page state, network activity, test data, and trace/debug output. The goal is to discover what Playwright was waiting for.

Can a wrong locator cause a timeout?

Yes. If the locator never identifies the intended element, Playwright can continue waiting until the relevant timeout is reached.


Conclusion

A Playwright timeout error is not simply a signal that Playwright needs more time.

It is often a diagnostic clue.

The best approach is to identify exactly what Playwright was waiting for. Check the locator, visibility, enabled state, navigation, API response, test data, and application state before changing timeout values.

Use Playwright's automatic waiting and web-first assertions whenever possible. Increase a timeout only when you understand the legitimate reason for the additional time.

For a structured learning path, you can continue with the PlaywrightMasters Playwright Roadmap and build these concepts into practical automation projects.


Comments

Popular posts from this blog

How to Run Only Smoke Tests in Playwright: Step-by-Step Guide

How to Test REST APIs Using Playwright

Playwright Multiple Tabs and Windows Explained: A Practical Guide