← Back to library
Playwrightwaitadvancedv1.20+

Wait for URL to change after an action

Use waitForURL() or toHaveURL() to wait for client-side navigation to complete after a click or submit.

1test('multi-step form advances the URL on each step', async ({ page }) => {
2  await page.goto('/onboarding/step-1');
3
4  await page.getByLabel('Company name').fill('Acme Corp');
5  await page.getByRole('button', { name: 'Next' }).click();
6
7  // waitForURL() blocks until the URL matches — safer than a fixed wait
8  await page.waitForURL('/onboarding/step-2');
9  await expect(page.getByRole('heading', { name: 'Step 2' })).toBeVisible();
10
11  await page.getByRole('button', { name: 'Next' }).click();
12
13  // toHaveURL() is the retrying assertion equivalent — use it in expect chains
14  await expect(page).toHaveURL(/step-3/);
15});
#waitForURL#toHaveURL#navigation#redirect#SPA