3.6 Locator handler
Locator handler is an automatic way to handle unexpected overlays on a web page, for example cookie banners or similar elements, which can appear at a random time during test execution. Although it is usually better to handle cookie banners by setting the cookie (for example with JavaScript), this is not always possible. In those cases, the Add Locator Handler Click and Add Locator Handler Custom keywords offer an automatic way to handle such popups.
These keywords register a waiter/handler that waits for elements to appear in the page. If an element is seen, it performs the action defined by the handler. There is a default handler that performs a click (for example on a button that accepts or denies cookies), and a custom handler that allows registering a custom set of actions: click, fill, check, and uncheck.
Exercise
Let’s look at a basic example with the Add Locator Handler Click keyword.
To use the page, your test should set up like this:
*** Settings ***
Library Browser
Library Dialogs
Test Setup Overlay Setup
*** Test Cases ***
Overlay Blocks Input
Type Text id=textInput Hello World
Pause Execution message=No overlay
Click id=openOverlay
Pause Execution message=There is overlay
Type Text id=textInput What is your name?
*** Keywords ***
Overlay Setup
VAR ${file} file://${CURDIR}/overlay.html
New Browser chromium False
New Page ${file}
Set Browser Timeout 5s
The Overlay Blocks Input test fails, because when the test clicks the id=openOverlay
element, it displays an overlay that blocks writing to the input element.
Your task is to use the Add Locator Handler Click keyword and register
a handler that will remove the overlay. As a bonus, configure the locator handler
to work only two times and make the test fail on the third attempt.
Solution
The solution can be found in the overlay.robot file.