Skip to content

Win Focus

Type: win-focus  ·  Package: Desktop Activities v1.0.8

Activates a window and brings it to the foreground (in front of the others). Useful when several applications are open and you need to make sure the keyboard and mouse go to the right window.

It locates the element by its selector —the window, or any control inside it— and activates the window that contains it: restores it if minimized, brings it to the front and waits up to timeout for Windows to confirm it is in the foreground. If that doesn’t happen, it fails.

The same timeout is used to find the element and to wait for the foreground.

ParameterTypeDefaultDescription
selectorselector—The window to focus (or a control inside it).
ParameterTypeDefaultDescription
sessionZoanDesktopSession—Win Attach session. Inside a body it is taken automatically; without a session, the selector must include the window.
timeoutint15000Maximum ms to wait for the window to reach the front (and to find the element). Empty = the project’s UI timeout; if not set, 15000 for the foreground and 30000 for the search.

This activity does not return a value.

MessageCause and fix
The window could not be activated within … ms.Windows would not bring the window to the front: a modal dialog from another application, the window runs as administrator and the robot doesn’t, or the session is locked. Check the machine with the robot’s account.
Element not found with selector {…}.See common errors.

Bring the application to the front before sending it a global keyboard shortcut:

Win Focus selector = (window "ERP")
Win Key Press keys = "f5"