Implementation:MarketSquare Robotframework browser Locator Handler Keywords
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, Overlay Handling |
| Last Updated | 2026-02-12 05:40 GMT |
Overview
Provides Robot Framework keywords for registering and removing automatic locator handlers that trigger when overlay elements become visible during page interactions.
Description
The LocatorHandler class extends LibraryComponent and contains three keywords:
- Add Locator Handler Click -- Registers a handler that automatically clicks a specified element whenever an overlay element (identified by selector) becomes visible. Supports configurable click count, delay, and force options. Internally delegates to Add Locator Handler Custom.
- Add Locator Handler Custom -- Registers a handler with a list of action specifications (dictionaries) that execute sequentially when the overlay element is visible. Supported actions are click, fill, check, and uncheck. Each action specification must include an action key and a selector key; fill actions additionally require a value key. Additional keys are passed as options to the Playwright API.
- Remove Locator Handler -- Removes a previously registered locator handler identified by its selector.
Handlers are tied to the active page and must be registered separately per page. The optional times argument limits how many times the handler fires before auto-removal. The noWaitAfter option (default True) controls whether Playwright waits for the overlay to disappear after the handler runs.
Usage
Use these keywords when your application under test displays unpredictable overlay elements (cookie consent dialogs, notification banners, modal popups) that can block interactions with underlying page elements. Register a handler once per page and let it automatically dismiss overlays during subsequent keyword execution.
Code Reference
Source Location
- Repository: MarketSquare_Robotframework_browser
- File: Browser/keywords/locator_handler.py
- Lines: 1-231
Signature
class LocatorHandler(LibraryComponent):
@keyword(tags=("Setter", "PageContent"))
def add_locator_handler_click(
self,
selector: str,
click_selector: str,
*,
noWaitAfter: bool = True,
times: int | None = None,
click_clickCount: int = 1,
click_delay: int = 0,
click_force: bool = False,
): ...
@keyword(tags=("Setter", "PageContent"))
def remove_locator_handler(self, locator: str): ...
@keyword(tags=("Setter", "PageContent"))
def add_locator_handler_custom(
self,
selector: str,
handler_spec: list[dict],
noWaitAfter: bool = True,
times: int | None = None,
): ...
Import
from Browser.keywords.locator_handler import LocatorHandler
I/O Contract
Add Locator Handler Click
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | selector | str | Selector for the overlay element whose visibility triggers the handler |
| Input | click_selector | str | Selector for the element to click when the handler fires |
| Input | noWaitAfter | bool | If True, does not wait for the overlay to hide after the handler runs (default: True) |
| Input | times | int or None | Maximum number of times the handler fires; None means unlimited |
| Input | click_clickCount | int | Number of clicks to perform (default: 1) |
| Input | click_delay | int | Delay in milliseconds between mousedown and mouseup (default: 0) |
| Input | click_force | bool | Bypass actionability checks and dispatch event directly (default: False) |
Add Locator Handler Custom
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | selector | str | Selector for the overlay element whose visibility triggers the handler |
| Input | handler_spec | list[dict] | List of action dictionaries, each with keys: action (click/fill/check/uncheck), selector, and optionally value (for fill) |
| Input | noWaitAfter | bool | If True, does not wait for the overlay to hide after the handler runs (default: True) |
| Input | times | int or None | Maximum number of times the handler fires; None means unlimited |
Remove Locator Handler
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | locator | str | Selector identifying the locator handler to remove |
Usage Examples
Robot Framework
*** Settings ***
Library Browser
*** Test Cases ***
Handle Cookie Consent Overlay With Click
New Page https://example.com
Add Locator Handler Click id=CookieOverlay id=AcceptCookiesButton
Type Text id:username testuser
Type Text id:password secret
Click id:login
Remove Locator Handler id=CookieOverlay
Handle Overlay With Custom Fill And Click Actions
New Page https://example.com
VAR &{fill_spec}
... action=Fill
... selector=id=overlayInput
... value=Hello
VAR &{click_spec}
... action=click
... selector=id=OverlayCloseButton
Add Locator Handler Custom id=overlay [${fill_spec}, ${click_spec}]
Type Text id:username user
Click id:login