UIA Viewer Issues

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
avedium
Posts: 3
Joined: 04 May 2024, 12:32

UIA Viewer Issues

Post by avedium » 08 May 2024, 12:18

Hello!

I am creating some scripts to automate repetitive tasks at work, and have been watching Descolada's tutorial series on UIA V2 here: https://www.youtube.com/playlist?list=PLg-VAp_I6_oTfdL9sUqcC7s61jcQW9K38

I am currently attempting to create a script that clicks on the toolbar for an application we frequently use at my place of work. Here is the code in question:

Code: Select all

#Requires AutoHotkey v2.0
#include .\UIA-v2-main\Lib\UIA.ahk

; Define main Window element
AeMShellEl := UIA.ElementFromHandle("Aloha Configuration Center : Quality Dining Burger King ahk_exe AeMShell.exe")
	
AeMShellEl.ElementFromPath({T:10}, {T:11, i:2}).Click("left") ; Click reports
ControlClick("x60 y170", winTitle) ; Click (hover over?) "Aloha Configuration Center"
ControlClick("x60 y170", winTitle) ; Click Data Distribution

At this time, the script will press "Reports" on the apps toolbar, but the ControlClick commands are not functional, and I am having a difficult time identifying and interacting with the element detailed in UIAViewer as follows:
image.png
image.png (85.84 KiB) Viewed 162 times

As you can see, this element is missing an automation ID, UIA path (bottom left), and condition path. The element in question is a button on the toolbar for Aloha Configuration Center and looks like this:
image.png
image.png (9.59 KiB) Viewed 162 times

I am new to scripting in general and am currently wrapping up the tutorial series, but none of the information provided so far assists with being able to identify/interact with this element.

Any advice welcomed! :) I hope to give back to this community for all the assistance I have received at some point in the near future.

Descolada
Posts: 1168
Joined: 23 Dec 2021, 02:30

Re: UIA Viewer Issues

Post by Descolada » 08 May 2024, 14:56

@avedium
Have you tried MenuSelect instead of UIA though? The code would be something like this:

Code: Select all

MenuSelect("Aloha Configuration Center : Quality Dining Burger King ahk_exe AeMShell.exe", , "Reports", "Aloha Configuration Center", "Data Distribution")
As for the UIA approach... Notice in UIAViewer top left "Window Info" section that the window doesn't have a title. This is because context menus are usually separate windows from the main window, and thus ElementFromHandle needs to be called for every such new context menu "window". In this case the code might look something like this:

Code: Select all

AeMShellEl.FindElement({Name:"Reports", Type:"MenuItem"}).Click() ; Click reports
if !(hWnd := WinWait("ahk_class WindowsForms10.Window.808.....",, 0.5)) ; Wait for the context menu. The ahk_class should be the Class(NN) value from UIAViewer
    throw Error("No context menu found")
menuEl := ElementFromHandle(hWnd).Highlight().Click() ; Click("left") or ControlClick() might work better, because UIAViewer sees only a Menu-type element, and usually MenuItem-type elements are clickable with the regular Click() method

if !(hWnd := WinWait("ahk_class WindowsForms10.Window.808.....",, 0.5)) ; Wait for the second context menu. You might need to use WinWaitActive or some other method instead, depending on how the window acts
    throw Error("No second context menu found")
secondMenuEl := ElementFromHandle(hWnd).Highlight().FindElement({Name:"Data Distribution"}).Click()

Post Reply

Return to “Ask for Help (v2)”