Implementation:MarketSquare Robotframework browser Interaction Grpc Handlers
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, gRPC Handlers |
| Last Updated | 2026-02-12 05:40 GMT |
Overview
Implements all user-interaction operations on page elements (click, type, select, hover, focus, checkbox, upload, dialogs, mouse, keyboard, scroll) via gRPC handlers in the Node.js Playwright wrapper.
Description
interaction.ts contains the gRPC handler functions that perform state-modifying user interactions on browser pages. Each function receives a protobuf request, resolves the target element via Playwright Locator, executes the interaction, and returns a gRPC response. The module covers:
- Click operations:
clickperforms standard clicks with configurable options (button, position, modifiers, force, click count). The internalinternalClickhelper gracefully handles "Target closed" errors that can occur when clicking triggers navigation.tapperforms touch tap events. - Text input:
typeTextsimulates keystroke-by-keystroke typing with configurable delay and optional pre-clear.fillTextsets input values directly (like paste) with optional force.clearTextempties input fields by filling with an empty string. - Key presses:
presssends keyboard shortcuts and key combinations on a specific element, supporting a list of keys with configurable press delay and inter-key delay. - Select option:
selectOptionselects options from<select>elements by value, label, or index matcher and returns the updated selection state.deSelectOptionclears all selections. - Hover and focus:
hovermoves the mouse over an element with configurable options (position, modifiers, force).focusgives keyboard focus to an element. - Checkbox:
checkCheckboxanduncheckCheckboxtoggle checkbox state, waiting for the element to be attached first and supporting force mode. - File upload:
uploadFileBySelectorsets files on an<input type="file">element, supporting both file paths and in-memory buffers (name, mimeType, buffer).uploadFilewaits for and responds to a file chooser dialog. - Dialog handling:
handleAlertsets up a one-time event handler for the next dialog (accept/dismiss with optional prompt input).waitForAlertsprocesses a sequence of expected dialog actions with timeouts. - Mouse operations:
mouseButtonperforms click/up/down mouse actions.mouseMovemoves the cursor to specific coordinates.mouseWheelscrolls via mouse wheel with deltaX/deltaY. - Keyboard operations:
keyboardKeyperforms down/up/press for individual keys.keyboardInputdoes virtual keyboard text entry via insertText or type action with delay. - Scrolling:
scrollToElementscrolls an element into the visible viewport if needed.
Usage
This module is invoked by the Python-side gRPC client when Robot Framework keywords such as Click, Type Text, Fill Text, Clear Text, Press Keys, Select Options, Hover, Focus, Check Checkbox, Uncheck Checkbox, Upload File By Selector, Handle Future Dialogs, Mouse Button, Keyboard Key, Keyboard Input, and Scroll To Element are called. It is not used directly by end users.
Code Reference
Source Location
- Repository: MarketSquare_Robotframework_browser
- File: node/playwright-wrapper/interaction.ts
- Lines: 1-305
Signature
export async function selectOption(
request: Request.SelectElementSelector, state: PlaywrightState
): Promise<Response.Select>
export async function deSelectOption(
request: Request.ElementSelector, state: PlaywrightState
): Promise<Response.Empty>
export async function typeText(
request: Request.TypeText, state: PlaywrightState
): Promise<Response.Empty>
export async function fillText(
request: Request.FillText, state: PlaywrightState
): Promise<Response.Empty>
export async function clearText(
request: Request.ClearText, state: PlaywrightState
): Promise<Response.Empty>
export async function press(
request: Request.PressKeys, state: PlaywrightState
): Promise<Response.Empty>
export async function click(
request: Request.ElementSelectorWithOptions, state: PlaywrightState
): Promise<Response.Empty>
export async function tap(
request: Request.ElementSelectorWithOptions, state: PlaywrightState
): Promise<Response.Empty>
export async function hover(
request: Request.ElementSelectorWithOptions, state: PlaywrightState
): Promise<Response.Empty>
export async function focus(
request: Request.ElementSelector, state: PlaywrightState
): Promise<Response.Empty>
export async function checkCheckbox(
request: Request.ElementSelector, state: PlaywrightState
): Promise<Response.Empty>
export async function uncheckCheckbox(
request: Request.ElementSelector, state: PlaywrightState
): Promise<Response.Empty>
export async function uploadFileBySelector(
request: Request.FileBySelector, state: PlaywrightState
): Promise<Response.Empty>
export async function uploadFile(
request: Request.FilePath, page: Page
): Promise<Response.Empty>
export async function handleAlert(
request: Request.AlertAction, page: Page
): Promise<Response.Empty>
export async function waitForAlerts(
request: Request.AlertActions, page: Page
): Promise<Response.ListString>
export async function mouseButton(
request: Request.MouseButtonOptions, page?: Page
): Promise<Response.Empty>
export async function mouseMove(
request: Request.Json, page?: Page
): Promise<Response.Empty>
export async function mouseWheel(
request: Request.MouseWheel, page?: Page
): Promise<Response.Empty>
export async function keyboardKey(
request: Request.KeyboardKeypress, page: Page
): Promise<Response.Empty>
export async function keyboardInput(
request: Request.KeyboardInputOptions, page: Page
): Promise<Response.Empty>
export async function scrollToElement(
request: Request.ElementSelector, state: PlaywrightState
): Promise<Response.Empty>
Import
import { Dialog, Page } from 'playwright';
import { PlaywrightState } from './playwright-state';
import { Request, Response } from './generated/playwright_pb';
import { emptyWithLog } from './response-util';
import { findLocator, invokeOnKeyboard, invokeOnMouse } from './playwright-invoke';
import { getSelections } from './getters';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| request.selector | string | Yes | CSS, XPath, or element=uuid selector identifying the target element |
| request.strict | boolean | No | Enable strict mode to fail when selector matches multiple elements |
| request.text | string | Conditional | Text to type or fill into the element |
| request.delay | number | No | Delay in ms between keystrokes (for typeText) |
| request.clear | boolean | No | Whether to clear the field before typing |
| request.force | boolean | No | Force the action even if element is not actionable |
| request.options | string (JSON) | No | JSON-serialized click/hover options (button, position, modifiers, clickCount) |
| request.keyList | string[] | Conditional | List of key names to press sequentially |
| request.matcherJson | string (JSON) | Conditional | Matcher for select option (value, label, or index) |
| request.path / request.pathList | string / string[] | Conditional | File path(s) for upload operations |
| request.alertAction | string | Conditional | Dialog action: "accept" or "dismiss" |
| request.promptInput | string | No | Text to enter in a prompt dialog |
| request.action | string | Conditional | Mouse/keyboard action type (click, up, down, press, insertText, type) |
| page | Page | Yes | Active Playwright Page instance |
| state | PlaywrightState | Yes | Current Playwright state with active browser/context/page |
Outputs
| Name | Type | Description |
|---|---|---|
| Response.Empty | gRPC Response | Confirmation with log message for most interaction operations |
| Response.Select | gRPC Response | Updated select option entries after selectOption |
| Response.ListString | gRPC Response | List of alert messages collected by waitForAlerts |
Usage Examples
*** Test Cases ***
Login Flow
Type Text id=username_field demo delay=50ms
Fill Text id=password_field mode
Click id=login_button
Select and Checkbox
Select Options By css=select.dropdown value option1
Check Checkbox id=agree_terms
Uncheck Checkbox id=newsletter
File Upload
Upload File By Selector id=file_chooser /path/to/file.pdf
Dialog Handling
Handle Future Dialogs accept
Click id=alerts
Mouse and Keyboard
Mouse Button click x=100 y=200
Mouse Move x=300 y=400
Keyboard Key press Enter
Keyboard Input type Hello World delay=50