Core Concepts

Units of Work

A Unit of Work (UOW) is GPAL's atomic block - any number of selectors followed by any number of actions, all operating on the same matched set of elements, until the next WithSelector starts a new UOW. One selector can match a hundred elements, and one action then applies to all of them.

Selectors and Actions, Not 1-to-1

A UOW is not 'one selector, one element, one action'. It is 'these selectors define a working set, these actions operate on that working set'. WithSelector adds to the current UOW's selectors. Calling an action does not end the UOW. It runs against everything the UOW's selectors matched, and you can call another action immediately after for the same set. The UOW only ends, and a new one begins, when WithSelector is called again.

One Selector, Many Elements, One Action

A selector is not limited to a single element. A CSS selector that matches 100 checkboxes on a page is still one selector - and a single LeftClick() against that UOW clicks all 100, one click per matched element, with no loop in your code. WithAllThatMatch can further control how many repeated elements a UOW operates on, including across paginated results.

// Pass a selector string directly -- no loop required

browser.LeftClick("input[type=checkbox]");

// WithAllThatMatch(10) limits to 10 rows per page

browser

.WithSelector(".row .select-item")

.WithAllThatMatch(10)

.LeftClick();

// Multiple actions, same UOW -- each makes a full pass before the next

browser

.WithSelector(".product-card")

.Hover()

.GetGrid(out var cards)

.LeftClick();

TIP

Where traditional automation code finds a list of elements and loops over it to click, type, or read each one, GPAL expresses the same intent as a single selector plus a single action. The 'loop' is implicit in the selector matching multiple elements - each action is its own complete pass over the matched set.

Data Flow Through UOWs

Because actions do not close the UOW's selector set, you can chain several actions back to back. Each action completes its own pass over every element the UOW's selectors matched before the next action starts - it is one loop per action, not one loop per element running every action. UOWs can also consume input data (FillInFrom a file, database, or grid) and produce output data (GetGrid writes matched element content into a grid). Output grid columns correspond to selectors; rows correspond to repeated elements found on the page. Multi-page scraping with WithNextPageButton or WithInfiniteScroll accumulates rows across pages within a single UOW.

WARNING

The UnitOfWork class is public for debugging inspection only. Never instantiate or manipulate it directly - all UOW state is managed internally by GPAL.