Core Concepts

Conditional Logic

Element Callbacks

CallIfFound fires after a selector finds and matches elements. You receive the browser or application object, the found and matched element lists, and the selector. CallIfNotFound fires when a selector finds no elements after all strategies are tried. Both can be attached at the selector level, the UOW level, or globally on GPAL. Return CallIfStatus.Handled to stop further callback propagation, or NotHandled to allow broader-scope handlers to also fire.

Three Scopes and Row Branching

Callbacks stack across three scopes -- selector, UOW, and global -- firing in order unless one returns Handled. CallAfterFillIn is a fourth point: it fires after each row of tokens is consumed during FillInFrom, giving you a per-record branching point to submit, evaluate, or continue.

// Selector-level: handle a cookie banner if present

var cookieBanner = GPAL.Selector

.WithCSS("#cookie-accept")

.CallIfFound((b, foundElements, matchedElements, selector, matchedAll) => {

matchedElements[0].Click();

return CallIfStatus.Handled;

})

.CallIfNotFound((b, foundElements, matchedElements, selector, matchedAll) => {

return CallIfStatus.Handled; // no banner - fine

})

.ToGPALObject();


// CallAfterFillIn: branch per row during a data-driven fill

browser.WithSelector(nameField)

.WithSelector(emailField)

.CallAfterFillIn((b, tokens, tokenIdx) => {

b.LeftClick(submitBtn);

return CallIfStatus.Handled;

})

.FillInFrom((GPALFile)"contacts.csv");

NOTE

CallAfterFillIn fires once per consumed row of data, not once per element. It runs after every row regardless of what was filled. Use it to take action after each record is processed.

Stop On Not Found

WithStopOnNotFound is a setting, not a callback. It terminates the workflow when a selector yields no results, after the CallIfNotFound handlers have run. It can be set globally on GPAL or per selector, and the workflow stops if either one is true. A common pattern is to set it false globally (non-critical selectors can miss) and true on specific selectors where a missing element means something is fundamentally wrong.

WARNING

When WithStopOnNotFound(true) is in effect and a selector finds nothing, CallIfNotFound is invoked first and the workflow halts after it returns. Returning Handled does not prevent the stop, so use CallIfNotFound to log the not-found case, not to recover from it.

💬 Ask GPAL