Skip to content

Playwright Page Navigation Not Working Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Playwright Page Navigation Not Working Fix. We cover key concepts, practical examples, and best practices.

Your Playwright test navigates but the page doesn't load — or the test proceeds before the navigation completes, causing element selection to fail.

The Problem

// WRONG — not awaiting navigation
test('navigate to profile', async ({ page }) => {
  page.goto('/profile');  // Missing await
  await page.locator('h1').waitFor();  // Fails — navigation hasn't started
});
TimeoutError: page.waitFor: Timeout 5000ms exceeded.
  waiting for locator('h1') to be visible

The goto returns a promise that resolves when navigation completes. Without await, the test races ahead.

Step-by-Step Fix

1. Always await navigation

// RIGHT — await page.goto
import { test } from '@playwright/test';

test('navigate to profile', async ({ page }) => {
  await page.goto('https://example.com/profile');
  await expect(page.locator('h1')).toHaveText('User Profile');
});

2. Use navigation options

// RIGHT — navigation with options
test('navigate with timeout', async ({ page }) => {
  await page.goto('https://example.com/profile', {
    timeout: 30000,
    waitUntil: 'networkidle',  // Wait for network to be idle
  });

  await expect(page).toHaveURL(/.*\/profile/);
});

3. Handle redirects

// RIGHT — follow redirects automatically
test('navigates through redirect', async ({ page }) => {
  await page.goto('https://example.com/old-path');

  // Playwright follows redirects by default
  await expect(page).toHaveURL(/.*\/new-path/);
});

4. Use page.waitForURL for navigation verification

// RIGHT — wait for specific URL
test('click navigates to new page', async ({ page }) => {
  await page.goto('https://example.com');

  await page.getByText('Go to Profile').click();
  await page.waitForURL('**/profile');

  await expect(page.locator('h1')).toHaveText('Profile');
});

Expected output:

✓ navigate to profile (1.2s)
✓ navigate with timeout (0.8s)
✓ click navigates to new page (1.5s)

Prevention Tips

  • Always await page.goto() and page.click() that trigger navigation
  • Use waitUntil options for different loading requirements
  • Use page.waitForURL() after navigation-triggering actions
  • Set appropriate timeouts for slow pages
  • Check URL assertions to confirm navigation completed

Common Mistakes with page navigate

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world PLAYWRIGHT code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What waitUntil option should I use?

load (default) waits for the load event. domcontentloaded waits for HTML parsing. networkidle waits for no network activity for 500ms. Use domcontentloaded for SPAs, networkidle for pages with many async requests.

Does page.goto follow redirects?

Yes. Playwright automatically follows HTTP redirects. The final URL is available via page.url() after navigation completes.

How do I navigate without page.goto?

Use page.click() on a link, page.fill() + page.press('Enter') on a search field, or page.evaluate(() => window.location.href = url). Then use page.waitForURL() to wait for navigation.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro