Browser

Callbacks and Conditional Logic

Methods for attaching custom logic that runs after data entry, when selectors match elements, or when selectors fail to find elements.

Methods for attaching custom logic that runs after data entry, when selectors match elements, or when selectors fail to find elements.

CallAfterFillIn registers a delegate that fires after each row of token data is consumed during a FillInFrom cycle. CallIfFound registers a delegate that fires when the selector finds matching elements. CallIfNotFound fires when the selector finds no matches. The Persistent variants (PersistentCallIfFound, PersistentCallIfNotFound) apply across all units of work for the lifetime of the browser session. RemoveCallIfHandlerEverywhere removes a handler from all units of work at once.

TIP

CallIfFound delegates receive the Browser instance, a list of found elements, a list of matched elements (after filtering), and the Selector. Return an integer status code - 0 to continue normally, other values to signal special handling.

Examples

GPAL Fluent: High-level fluent C# API

//Persistent handlers are useful for cross-cutting concerns - for example, a PersistentCallIfFound that dismisses cookie banners or handles session timeouts wherever they appear.

// Run logic after each form submission row GPAL.Browser .GoTo("https://example.com/form") .WithSelector("#name") .FillInFrom(customerGrid) .CallAfterFillIn((browser, grid) => { browser .WithSelector("#submit") .LeftClick(); return 0; }); // Conditional action when an element is found GPAL.Browser .GoTo("https://example.com") .WithSelector(".cookie-banner") .CallIfFound((browser, found, matched, sel) => { browser .WithSelector(".accept-cookies") .LeftClick(); return 0; });