Selector

Selector Callbacks

Attach conditional logic directly to a selector - run a delegate when elements are found or when no elements are found.

Attach conditional logic directly to a selector - run a delegate when elements are found or when no elements are found.

CallIfFound on a Selector registers a delegate that fires when this specific selector finds matching elements. CallIfNotFound fires when no matches are found. These selector-level callbacks are an alternative to setting them on the Browser or Application object - they are scoped to this one selector definition and travel with it when the selector object is reused across multiple units of work.

Examples

GPAL Fluent: High-level fluent C# API

//Selector-level callbacks are a clean way to package an element's conditional behavior alongside its locator definition. The delegate signature is the same as Browser/Application callbacks: (browser, foundElements, matchedElements, selector) returning an int.

// Create a reusable selector with built-in conditional logic var cookieBanner = GPAL.Selector .WithCSS(".cookie-consent") .WithSelectorName("Cookie Banner") .CallIfFound((browser, found, matched, sel) => { browser .WithSelector(".accept-all") .LeftClick(); return 0; }); // Reuse the selector on multiple pages GPAL.Browser .GoTo("https://example.com") .WithSelector(cookieBanner) .GoTo("https://example.com/about") .WithSelector(cookieBanner);