Selector

Selector Behavior and Engine

Methods for configuring how a selector behaves - stopping the workflow on failure, enabling scroll-based search, using OCR, naming the selector for logs, and selecting the interaction engine.

Methods for configuring how a selector behaves - stopping the workflow on failure, enabling scroll-based search, using OCR, naming the selector for logs, and selecting the interaction engine.

WithSelectorName assigns a human-readable name used in log and exception messages. WithStopOnNotFound(true) halts the entire workflow if the selector finds no elements - useful as a guard condition. WithSimulateMouse(true) moves the mouse naturally (with a short arc) to the element before interacting; without it, hardware-driven mouse input jumps directly to the element's coordinates with no movement in between. WithSearchForSelector(true) enables slow-scroll searching when an element is below the fold. WithOCR provides a text string to find on-screen using optical character recognition. WithHardware and WithJavaScript override how this one selector is interacted with - hardware-level mouse/keyboard emulation or direct JavaScript injection - regardless of the browser's base automation engine.

TIP

WithUseAutomationEngine on the Browser sets the base automation engine (PuppeteerPort, the default, Selenium, or OttoMagic) for the entire session and cannot be changed once the browser is open. A Hardware (HW) variant of that engine (SeleniumHW, PuppeteerPortHW, PuppeteerPipeHW, OttoMagicHW) makes hardware-level input the default for the whole workflow without touching individual selectors. WithHardware and WithJavaScript work at a different level - they override how one matched element is interacted with for that one selector, layered on top of whichever base engine is active, and still take effect even when a *HW engine is selected.

Examples

GPAL Fluent: High-level fluent C# API

//WithHardware and WithJavaScript are properties (no parentheses). They apply only to the selector they are chained from - the browser's base automation engine, set once via WithUseAutomationEngine before the first GoTo or Get, is fixed for the life of the session.

// Stop the workflow if a required element is missing var required = GPAL.Selector .WithCSS("#checkout-form") .WithSelectorName("Checkout Form") .WithStopOnNotFound(true); // Use JavaScript injection for a specific interaction var jsClick = GPAL.Selector .WithCSS("#hidden-trigger") .WithJavaScript; // Use OCR to find text on screen var ocrTarget = GPAL.Selector .WithOCR("Click to Continue");