Skip to content

E2E Test Timeout Waiting for Element

Error message

                TimeoutError: Waiting for selector failed after 30000ms
              

Quick summary

The E2E test waited for an element that never appeared within the timeout. The page might not have loaded, or the element doesn't exist.

Why this happens

  • The page didn't load correctly (network issue, wrong URL).

  • The element selector is wrong — typo or changed HTML structure.

  • The element appears after a slow async operation that exceeds the timeout.

  • The application has a bug that prevents the element from rendering.

  • Authentication or navigation failed silently.

Minimal example

✗ Broken code
test('login', async ({ page }) => {
  await page.goto('/login');
  await page.fill('#usr', 'alice');  // wrong selector
  await page.click('#submit');
  await page.waitForSelector('#dashbard'); // typo — never found
});
✓ Fixed code
test('login', async ({ page }) => {
  await page.goto('/login');
  await page.fill('#username', 'alice');
  await page.click('#submit');
  await page.waitForSelector('#dashboard'); // correct selector
});

Fix the selector to match the actual element ID on the page.

How to diagnose

  • Take a screenshot or video of the test run to see the actual page state.

  • Check if the page URL is correct after navigation.

  • Verify the selector matches the actual HTML (inspect the page manually).

  • Increase the timeout temporarily to see if it's just slow.

  • Check network logs for failed API calls that prevent rendering.

How to fix

  • Fix the selector to match the actual HTML structure.

  • Fix the page navigation or authentication flow.

  • Increase the timeout if the operation is legitimately slow.

  • Add explicit waits for intermediate states before looking for the final element.

  • Fix application bugs that prevent the element from rendering.

How to prevent

  • Use auto-waiting features (Playwright/Cypress wait automatically for elements).

  • Use resilient selectors (data-testid, role-based) that don't break on UI changes.

  • Take screenshots on failure for debugging.

  • Set appropriate timeouts for different operations.

Related Resources

Related Lessons

← Back to language