Playwright · Middle · Question 32 of 75

What does locator.or() do?

const dialog = page.getByText("Confirm security settings");
const newEmail = page.getByRole("button", { name: "New email" });
await expect(newEmail.or(dialog).first()).toBeVisible();
Show the answer

Correct answer: Matches either locator, for when one of two may appear

Explanation

It handles UIs that show one of two states. Use first() because both might match at once.

Further reading

Problem with a question

Playwright · Middle · question 32

Test yourself

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

Take this quiz