03-21-2025, 12:58 PM
QM UIA examples.
Macro UIA example - find by name and click
Macro UIA example - find by description and get parent
Macro UIA example - find by type and name
Macro UIA example - find by name and click
int w=win("Edge" "Chrome_WidgetWin_1")
str name="Extensions"
int nameFlags=0 ;;1 case-insensitive, 2 match substring
UIA.CUIAutomation8 uia._create
UIA.IUIAutomationElement ew=uia.ElementFromHandle(+w)
UIA.IUIAutomationCondition pc=uia.CreatePropertyConditionEx(UIA.UIA_NamePropertyId name nameFlags)
UIA.IUIAutomationElement ef=ew.FindFirst(UIA.TreeScope_Descendants pc)
out ef.CurrentName
sub.UiaClick ef
#sub UiaClick
function UIA.IUIAutomationElement&e
UIA.tagPOINT p
if 0!=e.GetClickablePoint(p)
,lef p.x p.y
else
,UIA.tagRECT r=e.CurrentBoundingRectangle
,lef r.left+r.right/2 r.top+r.bottom/2
#sub UiaClickAt
function UIA.IUIAutomationElement&e x y
UIA.tagRECT r=e.CurrentBoundingRectangle
lef r.left+x r.top+y
Macro UIA example - find by description and get parent
int w=win("Edge" "Chrome_WidgetWin_1")
str desc="Refresh"
int descFlags=2 ;;1 case-insensitive, 2 match substring
UIA.CUIAutomation8 uia._create
UIA.IUIAutomationElement ew=uia.ElementFromHandle(+w)
UIA.IUIAutomationCondition pc=uia.CreatePropertyConditionEx(UIA.UIA_FullDescriptionPropertyId desc descFlags)
UIA.IUIAutomationElement6 ef=+ew.FindFirst(UIA.TreeScope_Descendants pc)
out ef.CurrentFullDescription
UIA.IUIAutomationTreeWalker walk=uia.RawViewWalker
UIA.IUIAutomationElement ep=walk.GetParentElement(+ef)
UIA.tagRECT r=ep.CurrentBoundingRectangle
out F"{r.left} {r.top}"
Macro UIA example - find by type and name
int w=win("Edge" "Chrome_WidgetWin_1")
int role=UIA.UIA_ButtonControlTypeId
str name="Extensions"
int nameFlags=0 ;;1 case-insensitive, 2 match substring
UIA.CUIAutomation8 uia._create
UIA.IUIAutomationElement ew=uia.ElementFromHandle(+w)
UIA.IUIAutomationCondition pc=uia.CreateAndCondition(uia.CreatePropertyCondition(UIA.UIA_ControlTypePropertyId role) uia.CreatePropertyConditionEx(UIA.UIA_NamePropertyId name nameFlags))
UIA.IUIAutomationElement ef=ew.FindFirst(UIA.TreeScope_Descendants pc)
out ef.CurrentName