Skip to main content

3.6 Locator handler

Locator handler is an automatic way to handle unexpected overlays in the webpage, for example cookie banners or similar things, 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), in all cases this is not 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 one which performs a click (for example on a button that accepts or denies cookies), and a custom handler which 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 do setup 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 will display an overlay which blocks writing to the input element.

Your task is to use the Add Locator Handler Click keyword and register a handler which 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

Solution can be found in the overlay.robot file.

Loading examples...