@LAPIII, I haven't managed to reproduce the error with your provided code, perhaps your original code differs in significant ways? I recommend updating AHK, UIA, and UIA_Browser to the latest version if you haven't already (I also just pushed an update to UIA_Browser to make cUIA start faster in Edge).
I modified your code a bit. Firstly,
IsSet(ytEl) makes sure that ytEl is actually set by the time you try the hotkey. Sometimes UIA_Browser initiates slowly, so this makes sure
ytEl is actually set.
Then I had to change the path in the z hotkey. I think the Youtube or Edge layout changes from time to time, so it's usually better to avoid paths in browsers anyway.
Also I sped up the g hotkey with two optimizations:
cUIA.DocumentElement limits the search to only the document, which means tab elements, address bar etc won't be searched.
order:"PostOrder" makes the search happen from deepest element to the top, not from top to bottom.
Code: Select all
#Requires Autohotkey v2.0+
#NoTrayIcon
#Include <UIA>
#Include <UIA_Browser>
WinWaitActive "YouTube ahk_exe msedge.exe"
cUIA := UIA_Browser()
ytEl := UIA.ElementFromHandle("YouTube ahk_exe msedge.exe")
#HotIf WinActive("YouTube ahk_exe msedge.exe") && IsSet(ytEl)
z::ytEl.ElementFromPath("Y/YYY/YqYYYYVRRR0").Click() ; Guide Buttton
g::
{
cUIA.DocumentElement.FindElement({Type:"Button", Name:"Guide", order:"PostOrder"}).Click()
}
NOTE: You can disable UIAViewer "always on top" mode by right-clicking the status bar where the UIA paths are, and disabling "UIAViewer always on top" setting.