Browser

Mouse and Keyboard

LeftClick, LeftDoubleClick, MiddleClick, and RightClick operate on the element(s) matched by the current selector. Hover moves the mouse over the element without clicking. Focus makes the element the active element - if it's editable (an input, textarea, contenteditable, or anything with a text caret) Focus performs a real click first, placing the caret and readying it for typing; non-editable elements are focused/moved-to without a click. DragAndDrop drags the matched element to a target - configure the drop coordinates with a second selector or offset. SendString types a literal text string, dispatching real key events one character at a time - its pacing is controlled by GPAL.WithTypingDelay (default 0, no delay between characters); set it greater than 0 to slow typing down on every engine (Hardware, Selenium, Puppeteer, OttoMagic) by sleeping a random duration between Math.Min(25, TypingDelay) and TypingDelay milliseconds before each character. SendKey sends a virtual key code for special keys like Enter, Tab, and Escape. PressModifierKey and ReleaseModifierKey hold modifier keys across subsequent actions. Hide sets an element's CSS display to none, removing it from the page layout without deleting it from the DOM - available both as the fluent browser.WithSelector(selector).Hide() (workflow-based, hides every matched element) and as gpalElement.Hide() (element-based, hides one already-resolved element).

NOTE

A click dispatched through the browser's own input pipeline arrives at the page with isTrusted true, and a click made by script arrives with it false. Puppeteer clicks are the first kind without being asked. OttoMagic drives the page through its extension, so its clicks are script clicks, and a page that tests isTrusted can tell. Where that matters, run the workflow on Puppeteer.

Examples

GPAL Fluent: High-level fluent C# API

//SendKey accepts Windows virtual key codes (VK codes) as a byte. Common values: 0x0D = Enter, 0x09 = Tab, 0x1B = Escape, 0x41-0x5A = A-Z.

// Click a button

GPAL.Browser

.GoTo("https://example.com")

.WithSelector("#submit")

.LeftClick();


// Type text into an input

browser

.WithSelector("#search")

.SendString("GPAL automation")

.SendKey(0x0D); // Enter


// Ctrl+A then type (select all and replace)

browser

.WithSelector("#notes")

.PressModifierKey(ModifierKeys.Control)

.SendKey(0x41) // A

.ReleaseModifierKey(ModifierKeys.Control)

.SendString("replacement text");


// Focus an input before typing (clicks to place the caret since it's editable)

browser

.WithSelector("#search")

.Focus()

.SendString("GPAL automation");


// Hide an element - fluent (workflow) form

browser

.WithSelector(".cookie-banner")

.Hide();


// Hide an element - element-based form

gPalElement.Hide();

💬 Ask GPAL