Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:MarketSquare Robotframework browser Strict Mode Keywords

From Leeroopedia
Knowledge Sources
Domains Browser Automation, Configuration
Last Updated 2026-02-12 05:40 GMT

Overview

Provides the Robot Framework keyword for controlling Playwright strict mode, which determines whether element-matching selectors must resolve to exactly one element.

Description

The StrictMode class extends LibraryComponent and exposes a single keyword:

  • Set Strict Mode -- Toggles the library's strict mode on or off. When strict mode is enabled (True), any keyword that searches for elements using selectors will use Playwright's strict mode, which throws an error if the selector matches more than one element. When disabled (False), keywords operate on the first matched element without error. The keyword returns the previous strict mode value, enabling callers to save and restore it.

The scope argument controls the lifetime of the setting: Global persists across all suites, Suite persists within the current suite, and Test/Task persists within the current test or task.

Usage

Use Set Strict Mode when you need to temporarily relax strict matching (e.g., when interacting with elements that may have dynamic siblings) or to enforce strict matching in a specific test scope. Always capture the return value so you can restore the original mode afterward.

Code Reference

Source Location

Signature

class StrictMode(LibraryComponent):
    @keyword(tags=("Setter", "BrowserControl"))
    def set_strict_mode(self, mode: bool, scope: Scope = Scope.Suite) -> bool: ...

Import

from Browser.keywords.strict_mode import StrictMode

I/O Contract

Set Strict Mode

Direction Name Type Description
Input mode bool True to enable strict mode (selectors must match exactly one element), False to disable
Input scope Scope Lifetime scope: Global, Suite, or Test/Task (default: Suite)
Output return bool The previous strict mode value before the change

Usage Examples

Robot Framework

*** Settings ***
Library    Browser

*** Test Cases ***
Temporarily Disable Strict Mode
    ${old_mode}=    Set Strict Mode    False
    Get Text    //input    # Does not fail even if selector matches multiple elements
    Set Strict Mode    ${old_mode}

Enable Strict Mode Globally
    Set Strict Mode    True    scope=Global
    # All subsequent keywords will fail if a selector matches more than one element

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment