Application

Selector Targeting

WithSelector sets the active selector for the current unit of work using UI Automation element matching (AutomationID, Name, ClassName, XPath). WithAllThatMatch is used when a selector intentionally matches multiple repeating elements, such as rows in a list view. WithPersistentSelector adds a selector that persists across all units of work for the lifetime of the application session. PersistentCallIfFound and PersistentCallIfNotFound attach persistent handlers to the persistent selector.

NOTE

Application selectors use Windows UI Automation properties. The most reliable approach is WithAutomationID - match the AutomationId property from tools like Inspect.exe or Accessibility Insights. WithXPath is also supported for desktop element trees.

Examples

GPAL Fluent: High-level fluent C# API

//WithAllThatMatch takes an integer - the maximum number of elements to match and process. Set it high enough to cover the expected element count but not so high that it causes performance issues.

// Target by AutomationID (most reliable for desktop)

GPAL.Application

.Open("C:\MyApp\app.exe")

.WithSelector(GPAL.Selector.WithAutomationID("btnSave"))

.LeftClick();


// Target all rows in a list (repeating elements)

GPAL.Application

.Open("C:\MyApp\app.exe")

.WithSelector(GPAL.Selector.WithClassName("ListViewItem"))

.WithAllThatMatch(100)

.GetGrid(out var rows);

💬 Ask GPAL