Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:MarketSquare Robotframework browser Evaluation Grpc Handlers

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

Overview

Implements element location, JavaScript evaluation, element state waiting, selector recording, element highlighting, and file download operations via gRPC handlers in the Node.js Playwright wrapper.

Description

evaluation.ts is a core gRPC handler module in the Node.js layer of the Browser library. It provides the bridge between Robot Framework Python keywords and Playwright browser operations for evaluation and element resolution tasks. The module handles:

  • Element resolution: getElement and getElements resolve CSS/XPath selectors to Playwright Locator objects, storing UUID references in global state for the element=<uuid> syntax in RF keywords.
  • Strategy-based element finding: getByX implements Playwright's getByAltText, getByLabel, getByPlaceholder, getByRole, getByTestId, getByText, and getByTitle strategies with support for RegExp patterns, strict mode, and frame selectors.
  • JavaScript evaluation: evaluateJavascript executes arbitrary JavaScript on the page or on specific elements, supporting both page-level and element-scoped evaluation with optional arguments. It uses tryToTransformStringToFunction to convert string scripts into callable functions.
  • State waiting: waitForElementState waits for elements to reach specific DOM states (attached, detached, hidden, visible, or custom states via elementHandle).
  • Function waiting: waitForFunction waits for a JavaScript predicate to become truthy, optionally scoped to a specific element.
  • Selector recording: recordSelector injects the interactive selector-finder UI into the browser page, allowing users to visually pick CSS selectors. It exposes setRecordedSelector, getRecordedSelectors, and highlightPWSelector functions on the page.
  • Element highlighting: highlightElements and the internal highlightAll function create visual borders around matched elements with configurable duration, width, style, color, and mode (border/playwright/both).
  • File download: download programmatically triggers file downloads using fetch and blob URLs, coordinating with the network module's _waitForDownload.

Usage

This module is invoked by the Python-side gRPC client when Robot Framework keywords such as Get Element, Evaluate JavaScript, Wait For Elements State, Wait For Function, Record Selector, Highlight Elements, Add Style Tag, and Download are called. It is not used directly by end users.

Code Reference

Source Location

Signature

export async function getElement(
    request: Request.ElementSelector,
    state: PlaywrightState
): Promise<Response.String>

export async function getElements(
    request: Request.ElementSelector,
    state: PlaywrightState
): Promise<Response.Json>

export async function getByX(
    request: Request.GetByOptions,
    state: PlaywrightState
): Promise<Response.Json>

export async function evaluateJavascript(
    request: Request.EvaluateAll,
    state: PlaywrightState,
    page: Page
): Promise<Response.JavascriptExecutionResult>

export async function waitForElementState(
    request: Request.ElementSelectorWithOptions,
    pwState: PlaywrightState
): Promise<Response.Empty>

export async function waitForFunction(
    request: Request.WaitForFunctionOptions,
    state: PlaywrightState,
    page: Page
): Promise<Response.Json>

export async function addStyleTag(
    request: Request.StyleTag,
    page: Page
): Promise<Response.Empty>

export async function recordSelector(
    request: Request.Label,
    state: PlaywrightState
): Promise<Response.JavascriptExecutionResult>

export async function highlightElements(
    request: Request.ElementSelectorWithDuration,
    state: PlaywrightState
): Promise<Response.Empty>

export async function download(
    request: Request.DownloadOptions,
    state: PlaywrightState
): Promise<Response.Json>

Import

import { PlaywrightState } from './playwright-state';
import { Request, Response } from './generated/playwright_pb';
import { findLocator } from './playwright-invoke';
import { _waitForDownload } from './network';

I/O Contract

Inputs

Name Type Required Description
request.selector string Yes CSS, XPath, or element=uuid selector string
request.strict boolean No Enable strict mode (fail if selector matches multiple elements)
request.script string Conditional JavaScript code to evaluate (for evaluateJavascript, waitForFunction)
request.arg string (JSON) No Serialized argument to pass to the JavaScript function
request.allElements boolean No If true, evaluate against all matching elements
request.options string (JSON) No JSON-serialized options (state, timeout, etc.)
request.strategy string Conditional Selection strategy: AltText, Label, Placeholder, Role, TestId, Text, Title
request.duration number No Highlight duration in milliseconds
request.width string No Highlight border width (e.g. "3px")
request.style string No Highlight border style (e.g. "dotted")
request.color string No Highlight border color (e.g. "blue")
request.mode string No Highlight mode: "border", "playwright", or "both"
state PlaywrightState Yes Current Playwright state holding active browser/context/page

Outputs

Name Type Description
Response.String gRPC Response Single string result (element selector, evaluated value)
Response.Json gRPC Response JSON-serialized result (element arrays, function results, bounding boxes)
Response.JavascriptExecutionResult gRPC Response Result of JavaScript evaluation or selector recording
Response.Empty gRPC Response Confirmation with log message for void operations

Usage Examples

*** Test Cases ***
Get Element Example
    ${element}=    Get Element    css=h1#title
    Log    Found element: ${element}

Evaluate JavaScript Example
    ${result}=    Evaluate JavaScript    None
    ...    () => document.title
    Should Be Equal    ${result}    My Page Title

Wait For Elements State Example
    Wait For Elements State    id=loading-spinner    hidden    timeout=10s

Record Selector Example
    # Opens interactive selector picker in the browser
    ${selector}=    Record Selector    my_label

Highlight Elements Example
    Highlight Elements    css=.error-field    duration=3s

Download Example
    ${download_info}=    Download    https://example.com/file.pdf

Related Pages

Page Connections

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