Playwright · Middle · Question 20 of 75

How do you wait for a specific API response after a click?

const responsePromise = page.waitForResponse("**/api/orders");
await page.getByRole("button", { name: "Place order" }).click();
const response = await responsePromise;
Show the answer

Correct answer: Start waitForResponse before the click, then await it

Explanation

Starting to wait before the action avoids missing a fast response. You can then assert on its status or body.

Further reading

Problem with a question

Playwright · Middle · question 20

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