Application

Waiting

Methods for pausing execution until a specific time has passed, a UI element appears, or a named Windows window becomes visible.

Methods for pausing execution until a specific time has passed, a UI element appears, or a named Windows window becomes visible.

WaitFor(int waitForTimeInTicks) is dual-purpose, just like on Browser, but with a single integer-milliseconds overload: if called AFTER an action (LeftClick, FillInFrom, Open, etc.) it is a plain Thread.Sleep for that many milliseconds; if called BEFORE an action - right after WithSelector, with no action yet performed in this unit of work - it sets the maximum time GPAL will wait for the WithSelector elements to be found before continuing (CallIfNotFound fires if nothing is found in time). WaitForWindow waits for a Windows window with an exact title to appear on the desktop. WaitForWindowRegex waits for a window whose title matches a regular expression. WithWaitForWindowTimeout configures the maximum seconds to wait before WaitForWindow and WaitForWindowRegex give up. These methods are especially useful after triggering actions that open new windows or dialogs.

TIP

Application.WaitFor only takes a millisecond integer - there is no Selector or ElementState overload as there is on Browser. To wait for a specific element state in an Application workflow, combine WithSelector with CallIfNotFound, or poll with Until/While instead.

Examples

GPAL Fluent: High-level fluent C# API

//As with Browser, whether WaitFor(int) sleeps or waits-for-selector depends on whether an action has already been called in the current unit of work. WaitForWindow uses exact string matching on the window title. Use WaitForWindowRegex when the title contains dynamic content (timestamps, counts, record IDs) that changes between runs.

// WaitFor BEFORE an action - wait up to 5s for the menu item to be found GPAL.Application .Open("C:\MyApp\app.exe") .WithSelector(GPAL.Selector.WithAutomationID("btnProcess")) .WaitFor(5000) .LeftClick(); // WaitFor AFTER an action - plain sleep for 150ms between key presses GPAL.Application .PressModifierKey(ModifierKeys.Control) .SendKey(GPAL.VK_HOME) .WaitFor(150) .ReleaseModifierKey(ModifierKeys.Control); // Wait for a dialog to appear after clicking GPAL.Application .Open("C:\MyApp\app.exe") .WithSelector(GPAL.Selector.WithAutomationID("btnProcess")) .LeftClick() .WaitForWindow("Processing Complete") .WithSelector(GPAL.Selector.WithAutomationID("btnOK")) .LeftClick(); // Wait with regex and custom timeout GPAL.Application .WithWaitForWindowTimeout(30) .WaitForWindowRegex("Report.*Generated") .WithSelector(GPAL.Selector.WithAutomationID("btnClose")) .LeftClick();