Robust Selectors and Wait Times in Power Automate Desktop
Why selectors break in Power Automate Desktop, how to build them robustly, and how to use Wait actions for real wait times instead of fixed pauses.
When a UI automation built with Power Automate Desktop (PAD) suddenly fails with “Failed to get UI element” after weeks of running in production, that's almost never a coincidence. Usually something changed in the background that the selector can no longer find: an app update, a different screen resolution, a window that now takes a second longer to open than before. These two levers, robust selectors and clean wait times, decide whether a flow keeps running stably in unattended mode for months or has to be fixed manually every few days.
This guide shows you how selectors in PAD are built, which operators and variables make them dynamic, and how to replace fixed pauses with real synchronization using the right Wait actions. At the end you'll find a checklist to harden existing flows against the most common causes of failure.
Why selectors break in the first place
A selector in Power Automate Desktop describes exactly where a UI element sits in the hierarchy of an application or a web page. According to Microsoft, selectors are created when PAD captures properties such as name, class, or automation ID, plus the element's position in the UI structure. That very capture is what makes selectors sensitive to change. In the troubleshooting guide for unattended desktop flows, Microsoft names, among others, the following factors that can invalidate a previously working selector:
- Screen resolution and DPI scaling
- Application updates or changes to the user interface
- The operating system version
- Window size or mode, for example maximized versus windowed
- The state of an element, enabled or disabled
- User permissions, since an application can load differently depending on the profile
If you know where a selector typically breaks, you can build it from the start to withstand these variations instead of reacting only after the first failure.
How a selector is built: levels, attributes, operators
A selector consists of several levels chained together with the `>` character. Each level describes an element with its attributes in the form `element[Attribut1="Wert1"][Attribut2="Wert2"]`. A simple example from the documentation on building a custom selector shows an editor window: `:desktop > window[Name="Notizen.txt - Editor"][Process="Notepad"]`. The first level always starts with the root element `:desktop`, and every further level is a child of the previous one.
Operators instead of hard-coded values
The default operator Equals looks for an exact, hard-coded value. That works reliably for static applications, but quickly becomes a problem once window titles change dynamically, for example through a file name or a timestamp in the title. Power Automate provides five further operators for this:
- Not equal, checks for any value except a specific one
- Contains, finds elements that don't follow a fixed pattern but include a specific keyword
- Starts with, checks the beginning of a value
- Ends with, checks the end of a value
- Regular expression match, checks against a custom pattern based on the .NET regex engine
A window title like “Notizen.txt - Editor (2)” can be captured far more robustly with Starts with than with Equals, because the number in brackets at the end can vary without breaking the selector.
Variables for dynamic values
If an attribute value depends on a previous action, for example a file name that is only known at runtime, you can insert a variable into the selector using percent notation, such as `:desktop > window[Name="%WindowName%"][Process="Notepad"]`. That way the selector stays valid even when the expected value changes from run to run.
Using multiple selectors and fallback
A single UI element can have several selectors in PAD. If the first one fails, Power Automate automatically moves on to the next in the defined order, with no extra step needed in your flow. Using the Selection with re-capture button, or by copying an existing selector, you can create additional variants, for example one using Equals for the normal case and one using Contains or Regex as a fallback.
For especially unstable interfaces, such as terminal sessions or legacy applications without a clean UI hierarchy, Microsoft's same guide also recommends the image fallback, where PAD relies on image recognition instead of UI attributes whenever a regular selector no longer works.
Wait times instead of fixed pauses
Fixed “Wait” actions with a set number of seconds are a common reason why flows either run unnecessarily slowly or still access an element too early. Power Automate Desktop offers dedicated synchronization actions for this, which wait for the actual state of the application instead of blindly letting a time span pass.
- Wait for window pauses execution until a specific window opens, closes, gains focus, or loses focus. The search can be based on a UI element, on instance or handle, or on title and class.
- Wait for window content pauses until specific text or a UI element appears or disappears within a window, optionally including a check whether the element is enabled or disabled. This is exactly the action Microsoft recommends in the UI automation actions reference when a UI element isn't available yet at execution time.
- Wait for image waits until an image appears or disappears on screen or in the foreground window, including adjustable tolerance and a choice between simple and advanced image matching.
All three actions can be configured to fail with a timeout error once a defined time has passed, instead of waiting indefinitely. That matters for unattended flows, so a stuck window doesn't block the entire run but instead flows in a controlled way into error handling.
Testing and repairing selectors
Before a flow goes into unattended operation, it's worth testing every critical selector directly in the Selector Builder. If a selector still breaks, the “Repair selector” feature offers quick first aid: you re-capture the element with Ctrl+left-click, PAD compares the old structure with the new one and suggests a repaired selector, which you can still review before accepting it. If a selector contains variables, automatic repair doesn't work according to Microsoft, and only manual adjustment in the Selector Builder's text editor remains.
Checklist for stable flows in unattended mode
For flows that are meant to run permanently without supervision, Microsoft summarizes several recommendations that have proven themselves in practice:
- Store several selectors per element so a fallback can kick in
- Build selectors with static attributes and catch dynamic parts using operators or variables
- Use the image fallback wherever UI attributes aren't reliable enough
- Set up a retry policy in the error handling of every critical action
- Choose the right action type, web automation for web elements, UI automation for desktop elements
- Make sure the application starts in the same window mode in unattended mode as in the attended test
- Re-capture and test the selector directly on the unattended machine
With this combination of robust selectors and real wait conditions, a flow runs into dead ends far less often. You stay in control of the process, because every action only starts once the application is actually ready for it, instead of setting off after an estimated wait time and hoping for the best. Anyone using Power Automate Desktop productively on a larger scale should plan these stability measures in from the start, for example as part of guided automation projects, rather than retrofitting them only after the first nightly failures.
Frequently asked questions
Why isn't a simple “Wait” action with a fixed number of seconds enough?
A fixed wait time only estimates how long an application needs, but doesn't react to its actual state. If the application is faster, the flow wastes time unnecessarily; if it's slower, for example due to network load or a slow server, the next action tries to access an element that isn't there yet. Actions like Wait for window content or Wait for window instead check the application's real state and only continue once the condition is actually met.
What's the difference between “Wait for window” and “Wait for window content”?
Wait for window refers to the window as a whole, that is whether it opens, closes, gains focus, or loses focus. Wait for window content goes one level deeper and checks whether specific text or a specific UI element appears, disappears, or changes its enabled or disabled state inside an already open window. In practice you often combine both: wait for the window first, then for the actual content.
How many selectors should I set up per UI element?
There's no fixed number, but Microsoft explicitly recommends storing several selectors per element so a fallback kicks in if the first one fails. In practice, two to three variants are enough for most elements, for example one with Equals for the normal case, one with Contains or Regex as a fallback, and for particularly unstable interfaces an additional image fallback.
Can a selector with variables be repaired automatically?
No. According to Microsoft's documentation, the automatic repair function doesn't work for selectors that contain one or more variables. In that case you either have to temporarily replace the variables with static values to use the repair, or adjust the selector directly by hand in the Selector Builder's text editor.
What do I do if a selector keeps breaking despite repair and fallback?
If even a repaired selector with several fallback levels doesn't run stably, switching to the image fallback or to surface automation with mouse, keyboard, and OCR actions often helps, according to Microsoft, especially for applications without a clean UI hierarchy, for example in virtual desktop environments. It's also worth looking at the underlying cause: it's often a difference in screen resolution, DPI scaling, or window mode between the development environment and the unattended target machine.
NordFlux UG (haftungsbeschränkt)
NordFlux builds digital employees for organisations: automations and AI agents that take over repetitive work. You stay in control.
Concrete questions about automation or AI?
In a free initial analysis we discuss your case directly. No strings attached.