How to focus on a window

Symptom

UI automation actions cannot focus on a window. Depending on the nature of the app, a "Focus window" action may not be able to bring the window to focus. Even if the window is in the foreground, the focus may not be on the window, causing subsequent actions to fail.

Verifying issue

To verify that the "Focus window" action cannot bring the window to focus, send some keystrokes on the window using the "Send keys" action. If the window is not focused, the keystrokes won't be sent to the right place.

Workaround

Send a click on the window. In addition to the "Focus window" action, send a click afterwards to make sure that the window becomes focused. The following actions can be used to send a click on a window: 

  • Click UI element in window

  • Move mouse to image and send a click

  • Send mouse click

  • Move mouse to text on screen (OCR) and send a click

Need more help?

Expand your skills
Explore Training
Get new features first
Join Microsoft Insiders

Was this information helpful?

Thank you for your feedback!

Thank you for your feedback! It sounds like it might be helpful to connect you to one of our Office support agents.

×