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 Evaluation Keywords

From Leeroopedia
Revision as of 11:29, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/MarketSquare_Robotframework_browser_Evaluation_Keywords.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Browser Automation, JavaScript Execution
Last Updated 2026-02-12 05:40 GMT

Overview

Provides Robot Framework keywords for executing JavaScript on pages or elements, highlighting elements, injecting CSS style tags, and downloading files.

Description

The Evaluation class extends LibraryComponent and contains four keywords:

  • Evaluate JavaScript -- Executes arbitrary JavaScript on a page or against specific element(s) resolved by a selector. Supports passing JSON-serializable arguments and operating on all matched elements via the all_elements flag. Uses strict mode when all_elements is False.
  • Highlight Elements -- Adds a visual highlight (border or Playwright native mode) to elements matching a selector. Returns the count of highlighted elements. Configurable duration, width, style, color, and mode.
  • Add Style Tag -- Injects a <style type="text/css"> tag with raw CSS content into the current page frame.
  • Download -- Downloads content from a given URL using the current page's local state (cookies, session/local storage) to avoid authentication issues. Returns a DownloadInfo dictionary containing saveAs path, suggestedFilename, state, and downloadID.

All keywords communicate with the Playwright Node.js backend via gRPC.

Usage

Use Evaluate JavaScript when built-in keywords do not cover a specific DOM interaction or data extraction need. Use Highlight Elements for visual debugging or test documentation screenshots. Use Add Style Tag to inject custom CSS before taking screenshots or validating visual states. Use Download to programmatically retrieve files using the authenticated session of the current page.

Code Reference

Source Location

Signature

class Evaluation(LibraryComponent):
    @keyword(name="Evaluate JavaScript", tags=("Setter", "Getter", "PageContent"))
    def evaluate_javascript(
        self,
        selector: str | None = None,
        *function: str,
        arg: Any = None,
        all_elements: bool = False,
    ) -> Any: ...

    @keyword(tags=("Setter", "PageContent"))
    def highlight_elements(
        self,
        selector: str,
        duration: timedelta = timedelta(seconds=5),
        width: str = "2px",
        style: str = "dotted",
        color: str = "blue",
        *,
        mode: HighlightMode = HighlightMode.border,
    ): ...

    @keyword(tags=("Setter", "PageContent"))
    def add_style_tag(self, content: str): ...

    @keyword(tags=("Page Content",))
    def download(
        self,
        url: str,
        saveAs: str = "",
        wait_for_finished: bool = True,
        download_timeout: timedelta | None = None,
    ) -> DownloadInfo: ...

Import

from Browser.keywords.evaluation import Evaluation

I/O Contract

Evaluate JavaScript

Direction Name Type Description
Input selector str or None Optional selector to resolve an element handle passed as the first argument to the JS function
Input *function str One or more strings forming the JavaScript function or function body (joined with newlines)
Input arg Any Additional JSON-serializable argument passed to the function
Input all_elements bool If True, all matched elements are passed as an array; if False, strict mode applies (default: False)
Output return Any Deserialized JSON result from JavaScript evaluation, or empty string if no result

Highlight Elements

Direction Name Type Description
Input selector str Selector identifying elements to highlight
Input duration timedelta How long the highlight remains visible (default: 5s; 0s means permanent)
Input width str Border width (default: "2px")
Input style str Border style (default: "dotted")
Input color str Border color (default: "blue")
Input mode HighlightMode Highlight mode: "border" (classic) or "playwright" (native)
Output return int Number of elements highlighted

Add Style Tag

Direction Name Type Description
Input content str Raw CSS content to inject into the page

Download

Direction Name Type Description
Input url str URL of the file to download
Input saveAs str Persistent save path; empty means auto-generated GUID path (deleted on context close)
Input wait_for_finished bool If True, blocks until download completes (default: True)
Input download_timeout timedelta or None Timeout for the download when wait_for_finished is True (default: no timeout)
Output return DownloadInfo Dictionary with keys: saveAs, suggestedFilename, state, downloadID

Usage Examples

Robot Framework

*** Settings ***
Library    Browser

*** Test Cases ***
Execute JavaScript On Page
    New Page    https://example.com
    ${title}=    Evaluate JavaScript    None    () => document.title
    Log    Page title: ${title}

Execute JavaScript On Element
    ${active}=    Evaluate JavaScript    input#username
    ...    (element) => document.activeElement === element

Collect Text From All Buttons
    ${texts}=    Evaluate JavaScript    button
    ...    (elements, arg) => {
    ...        let text = []
    ...        for (e of elements) { text.push(e.innerText) }
    ...        text.push(arg)
    ...        return text
    ...    }
    ...    all_elements=True
    ...    arg=Extra text

Highlight Login Button
    Highlight Elements    input#login_button    duration=200ms
    ${count}=    Highlight Elements    input#login_button    duration=200ms    width=4px    style=solid    color=red

Inject Custom CSS
    Add Style Tag    \#username_field:focus {background-color: aqua;}

Download A File
    New Context    acceptDownloads=True
    New Page    https://example.com/downloads
    ${file_object}=    Download    https://example.com/file.txt
    ${actual_size}=    Get File Size    ${file_object.saveAs}

Related Pages

Page Connections

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