Application

Selector Paths

A path is a series of steps separated by slashes, each naming a control type and optionally narrowing it. Attributes are written in repeated brackets and are combined: Pane[@AutomationId='main'][@ClassName='Shell']. Three attribute names are understood, Name, AutomationId and ClassName, and each is an exact, case-sensitive match with no wildcards. A position picks one of several matches: Pane[2] is the second Pane, counting from one. A double slash skips levels: Window//Button finds the button at any depth below the window. A step that names only a control type usually matches more than one element, and the walk tries each match in turn until the rest of the path succeeds, so an ambiguous step does not fail the path. A step written with a position is exempt: it names that one element and nothing else, which is what makes it useful as a last resort.

NOTE

Naming every level makes a path that is right in one window and wrong in the next, because the anonymous containers in between differ by application version and by view. Name the levels that carry an AutomationId or a ClassName worth pinning, and let the double slash cover the rest. A path that is right in both shapes is worth more than one that is precise about a shape that changes. The cost is that a descendant step searches everything below its starting point, so use it to skip anonymous containers rather than as the default shape of every path.

Examples

GPAL Fluent: High-level fluent C# API

///Desktop/Window means your program's window. Desktop is ignored entirely, and is only there because the recorder writes paths starting from the desktop. Window matches your program's own window, and everything after that is looked for inside it. If the second step is anything other than Window, the search starts at the actual desktop and looks at every open window instead, which is how a right click menu is found: the menu is not inside your window, it is sitting on top of everything. When a path finds nothing, GPAL publishes the step it stopped at and lists what was actually there, which is usually enough to correct it without a recorder.

// name what has an identity and skip what does not

Selector fileList = (Selector)GPAL.Selector

.WithSelectorName("FileList")

.WithXPath("/Desktop/Window[@ClassName='CabinetWClass']//Pane[@AutomationId='listview']/List");


// several attributes on one step, combined

Selector toolbar = (Selector)GPAL.Selector

.WithSelectorName("Toolbar")

.WithXPath("/Desktop/Window/Pane[@ClassName='ReBarWindow32']/ToolBar/Button[@AutomationId='Item 42002']");


// a position, for two siblings nothing else tells apart

Selector secondPane = (Selector)GPAL.Selector

.WithSelectorName("SecondPane")

.WithXPath("/Desktop/Window/Pane[2]");

💬 Ask GPAL