Application

File Dialogs

LeftClickAndOpen clicks the element that raises an Open dialog, waits for the dialog, and answers it with the file or folder given. LeftClickAndSave does the same for a Save dialog, and deletes an existing file of that name first so the dialog never asks whether to replace it. AnswerFileDialog answers a dialog that is already on screen, for one raised by a keystroke or by the application itself. All three take a GPALFile, and a GPALFile naming several files answers a dialog that allows more than one. The same calls cover the folder picker, because it is the same dialog underneath.

NOTE

The path goes into the file name field through ValuePattern and the accept button is invoked, so nothing is typed and the window does not need focus. That is what lets a dialog be answered on a desktop that is not receiving input, which typing into it could never do. The dialog is recognised by its shape rather than its title: an accept button with AutomationId 1 beside a file name field or a folder tree. A title is the application's to choose and the user's language to write, and is not something to match on. The older folder picker, the one WinForms still raises, has a tree and no field, and is walked a path segment at a time instead.

Examples

GPAL Fluent: High-level fluent C# API

//The wait for the dialog uses WithWaitForWindowTimeout, the same setting WaitForWindow uses. When no dialog appears, or the dialog has no field and no tree, or it is still on screen after being accepted, GPAL publishes an error naming what it found instead. Deleting before saving is why LeftClickAndSave exists as a separate call: a prompt that cannot happen cannot be missed, mistimed, or worded differently on the next version of Windows.

// click the thing that raises an Open dialog and answer it

myApplication

.WithSelector(openMenuItem)

.LeftClickAndOpen(@"C:invoicesmarch.pdf");


// save over a file that already exists, which is deleted first

myApplication

.WithSelector(saveAsMenuItem)

.LeftClickAndSave(@"C: eportssummary.txt");


// a dialog raised by a keystroke, answered in the same chain

myApplication

.WithSelector(editorPane)

.LeftClick()

.PressModifierKey(ModifierKeys.Control | ModifierKeys.Alt)

.SendString("s")

.ReleaseModifierKey(ModifierKeys.Control | ModifierKeys.Alt)

.AnswerFileDialog(@"C: eports yped.txt");


// a folder picker is the same dialog and the same call

myApplication

.WithSelector(openFolderMenuItem)

.LeftClickAndOpen(@"C:projectscurrent");

💬 Ask GPAL