Playwright · Middle · Question 67 of 75
How do you handle a cookie consent banner that appears randomly?
- 1Use
force: trueon every click in the suite - 2Add
waitForTimeout(5000)in every test to wait for it - 3Use
page.addLocatorHandlerto close it when it appears
Show the answer
Correct answer: Use page.addLocatorHandler to close it when it appears
Explanation
A locator handler runs whenever the overlay blocks an action, then the action continues. Setting a consent cookie up front is another option.