Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 38 ยท Desktop Flows

Recorders, UI Elements and Selectors

Record clicks and typing into a desktop flow, capture UI elements, and make selectors robust so the flow keeps working when a window changes. Includes a selector-matching stand-in.

A desktop flow clicks a button. But which button? The program may show a dozen, in different positions on different days. Power Automate for desktop solves this by remembering each target as a UI element: a named object that holds a selector, a small description of how to find the control again. Understanding selectors is the difference between a flow that runs for years and one that breaks every Monday.

This lesson covers the recorders, the UI elements pane, how to edit selectors, waiting for screens to be ready, and the fallback of image-based clicks. The product runs only on Windows, so the steps are described in words and the runnable example is a stand-in that matches selectors against a made-up screen.

Two ways to create UI actions

Add actions manually. Use the action Click UI element in window (UI automation group), and in its dialog choose Add UI element. The designer shows a live capture: you hover over a control in the target application, hold Ctrl and click, and the control is stored as a UI element. Repeat for each control.

Use a recorder. The toolbar has a Recorder button with two modes:

  • Desktop recorder records mouse clicks and typing in Windows applications.
  • Web recorder records actions in a browser (it needs the Power Automate browser extension for your browser).

Press Record, perform the task once (the recorder shows the actions as you go), press Finish, and the actions land in your workspace, each with its UI element. Treat the result as a draft: recorders capture every click, including mistakes, and often use selectors that are too specific.

What a selector is

A UI element's selector is a chain from the window down to the control, each link made of a type and attributes. A simplified web example reads like this:

TEXT
html > body > form[Id="login"] > input[Name="email"]

A desktop application selector has the same idea: a window link (identified by name, class or process) followed by the control (a button, an edit box) with attributes such as Name, Id, Class and Text. The UI element picker shows the full selector and lets you edit it:

  • Tick or untick attributes to decide what must match.
  • Edit values to use wildcards or parameters.
  • Test the selector against the open window. A green result means one match was found.

Selectors can also contain variables, written between percent signs, so one element can serve many rows (for example a table cell that depends on %RowNumber%).

Making selectors robust

Problem Why it breaks Fix
Window title contains a changing value (a file name, a counter) The title no longer matches Remove the title attribute or use a wildcard match on the stable part
Selector uses a position or index ([3]) A new row or banner shifts the index Prefer Id, Name or Automation id
Dynamic ids (btn_8472) The number changes each run Match on a stable part or another attribute
Control is not on screen yet The page or window is slow Add Wait for window content, Wait for web page content or a wait for UI element
Two controls match Wrong one gets clicked Add an attribute until the Test shows one match

General rules: use the fewest attributes that still identify the control uniquely, prefer ids and names over positions, and always test after editing.

JS Stand-in: does this selector match one control?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Waiting for the screen

The most frequent cause of flaky desktop flows is speed: the flow clicks before the window is ready. Do not fix this by adding long fixed Wait actions everywhere; that makes flows slow and still unreliable. Use conditional waits:

  • Wait for window content or Wait for web page content (wait until an element or text appears).
  • Wait for process when an application must start first.
  • The Launch actions (Launch new Microsoft Edge, Run application) return only when the program is started, but its window may still be loading.

Set a timeout on every wait and check the outcome: if the element never appears, take the On block error path (error handling) rather than clicking blindly.

Images and coordinates: the last resort

When a control is invisible to Windows (a remote desktop window, a game-like canvas, a bitmap-only application), you can store a screenshot of the control in the Images pane and use an action such as Move mouse to image or Click on image. Matching depends on resolution, scaling, theme and colors, so run the flow on a machine with the same display settings. Absolute mouse coordinates are even more fragile. Use these only when UI elements cannot find the control.

Typing and keyboard actions

  • Populate text field in window sets a field's text directly. It is quicker and more reliable than typing keys.
  • Send keys simulates typing, including special keys written in braces such as and ; use it when a field does not accept direct text.
  • Press/release key and Set window state (focus, maximize) help with tricky windows. Make sure the right window has focus before sending keys, or the text goes to the wrong place.

A mini checklist before saving a recorded flow

  1. Delete accidental clicks.
  2. Rename UI elements ("Login button", not "UI element 7").
  3. Simplify and test each selector.
  4. Replace fixed waits with conditional waits.
  5. Put credentials into variables or secure inputs, never typed into an action.
  6. Run it three times, including once with the window starting in a different state.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a selector in a desktop flow?

    A UI element stores a selector: the chain of attributes that identifies a control.
  2. 2. A recorded flow breaks when a row is inserted above the target. Which selector detail is the likely cause?

    Index-based selectors shift when the layout changes. Prefer Id or Name.
  3. 3. What is better than a long fixed Wait before a click?

    Conditional waits finish as soon as the screen is ready and fail visibly on timeout.
  4. 4. When are image-based clicks appropriate?

    Images depend on resolution, scaling and theme, so they are the most fragile method.

Summary

  • Recorders capture a draft flow; UI elements store selectors that find controls again.
  • Keep selectors minimal and stable: prefer Id and Name over positions and changing titles, and test them.
  • Use conditional waits with timeouts instead of long fixed waits.
  • Use images or coordinates only when nothing else works, and populate fields directly rather than sending keys when possible.

Next: Variables, Excel and Files in Desktop Flows