Playwright · Senior · Question 23 of 77

Which pattern often causes flaky tests after a click that navigates?

await page.getByRole("link", { name: "Orders" }).click();
const title = await page.locator("h1").textContent();
expect(title).toBe("Orders");
Show the answer

Correct answer: Reading text once, before the new page has loaded

Explanation

textContent() doesn't wait for the new heading, so it may read the old page. await expect(page.locator('h1')).toHaveText('Orders') retries.

Further reading

Problem with a question

Playwright · Senior · question 23

Test yourself

Take the Playwright · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz