UI Automation study: principles, Win32 comparison, and findings

UIA versus Win32

Windows UI Automation (UIA) exposes a semantic tree of GUI elements. Each element has properties such as AutomationId, Name, ClassName, ControlType, visibility, and bounding rectangle. Supported patterns describe actions: InvokePattern for buttons, ValuePattern for text fields, and SelectionItemPattern for selectable items. The implementation uses pywinauto and comtypes to reach these COM interfaces.

Classic Win32 automation primarily works with HWNDs, window classes, messages, and coordinates. Win32 enumeration can discover native top-level windows, but does not necessarily expose the logical descendants of a WPF/DevExpress GUI. UIA exposes more meaningful structure for those controls. Conversely, UIA cannot guarantee that a control exposes a usable pattern: the graph’s context menu is opened with a coordinate-based right click, and submenu navigation uses mouse movement/clicks. These are complementary approaches, not interchangeable interfaces.

The exploratory 20_inspect_export_uia.py used win32gui.EnumWindows() to enumerate top-level windows while inspecting controls through UIA. The production SmartLabUIA does not import win32gui; it uses UIA and pywinauto.mouse for the relevant operations. Do not conflate the investigation method with the production implementation.

Element lookup strategy

The main window is selected using both a title containing SmartLab Studio II and AutomationId=mainShellWindow. For fixed parameter paths, the implementation traverses known parent/child edges using TreeScope_Children rather than performing a broad descendant search at every step. An unnamed ScrollViewer is located by ClassName. This limits ambiguous matches when repeated AutomationIds or labels exist. Dynamic dialogs are located separately; the filename input within the Windows Save dialog is resolved through the known sequence of nested child elements.

Investigation sequence (2026-11)

  1. 19.py: identified Z-axis Basic tab, scan/move/slit groups, and AutomationIds for parameter controls. This underpins BASIC_PATH, group paths, and PATHS.

  2. 20_inspect_export_uia.py: inspected context menus, exportDataWindow, its exportBtn, and the Windows Save dialog (#32770), filename edit (1001) and Save button (1). This investigation established the export UI elements.

  3. 21_test_export_uia.py, 22_inspect_export_hierarchy.py: explored lookup behavior around context menus. Changes to search strategy did not establish a replacement for the verified 20 findings; do not treat these scripts as a new canonical tree.

  4. 24_inspect_graph_uia.py: identified the display area’s 2θ/θ document, graphCtrl and chartControl, and its tab TwoThetaThetaTabId. The captured graph was offscreen; the implementation selects its tab before right-clicking.

Export investigations since the v0.2.6 tag

Study

What it checks

30

UIA context-menu requests to the chart and its hit targets

31

Direct WM_CONTEXTMENU and subsequent UIA saving

32

Coordinates and UIA paths for both clicks. The chart center hit the legendDock legend

33

Direct right-button messages versus SendInput

34

UIA submenu expansion, item selection, and saving after manually opening the menu

35

Repeated runs of the original API and desktop input permissions

36

Tab selection versus actual keyboard focus and context-menu key behavior

38

Compare UIA, WM_CONTEXTMENU, and SendInput on the 2θ graph after measurement

39

Add waits and retries around the existing API in the test process and save 2θ to a separate file

Study 34 verified UIA saving for both 2θ and 2θ/θ after manually opening the menu. Production export in v0.2.7 uses the existing combination of mouse clicks and UIA. Current sequence and verification

Lessons for future investigations

Record each element’s full parent chain, AutomationId, Name, ClassName, ControlType, supported patterns, visibility and bounding rectangle, together with the GUI state at capture time. Distinguish offscreen controls from missing controls. Keep investigation scripts separate from production code. Avoid replacing a verified parent-child path with a speculative global search; only add a new path after obtaining corresponding UIA evidence. Track the GUI version and distinguish a click request from confirmation that the underlying operation completed.