UIA v2

Post your working scripts, libraries and tools.
Descolada
Posts: 1188
Joined: 23 Dec 2021, 02:30

Re: UIA v2

21 May 2024, 23:18

@shipaddicted try y.FindElement({Type:"Edit", not:{Value:""}}).SetFocus() (if SetFocus() doesn't work, try Select() instead).

@redrum notice that UIAViewer doesn't show the tree for the webpage, and in "Window Info" section the title is empty and window class is different. That means that the context menu is a separate window from the main one and you need to use ElementFromHandle for that separately. Try this:

Code: Select all

+F8::
{
        discordImage := UIA.GetFocusedElement()
        discordImage.Click("R") ; try ShowContextMenu() as well
        if (hWnd := WinWait("ahk_class Chrome_WidgetWin_2",, 1000)) {
            Sleep 40 ; this might not be necessary if the UIA tree for the context menu is created fast enough by Brave
            contextMenu := UIA.ElementFromHandle(hWnd)
            contextMenu.FindElement({Name:"Copy link address"}).Highlight()
        }
}
redrum
Posts: 100
Joined: 25 Jan 2015, 22:57

Re: UIA v2

22 May 2024, 14:32

Descolada wrote:
21 May 2024, 23:18
@shipaddicted try y.FindElement({Type:"Edit", not:{Value:""}}).SetFocus() (if SetFocus() doesn't work, try Select() instead).

@redrum notice that UIAViewer doesn't show the tree for the webpage, and in "Window Info" section the title is empty and window class is different. That means that the context menu is a separate window from the main one and you need to use ElementFromHandle for that separately. Try this:

Code: Select all

+F8::
{
        discordImage := UIA.GetFocusedElement()
        discordImage.Click("R") ; try ShowContextMenu() as well
        if (hWnd := WinWait("ahk_class Chrome_WidgetWin_2",, 1000)) {
            Sleep 40 ; this might not be necessary if the UIA tree for the context menu is created fast enough by Brave
            contextMenu := UIA.ElementFromHandle(hWnd)
            contextMenu.FindElement({Name:"Copy link address"}).Highlight()
        }
}
Works great, thanks!
shipaddicted
Posts: 108
Joined: 15 Jul 2016, 19:57

Re: UIA v2

22 May 2024, 20:33

Descolada wrote:
21 May 2024, 23:18
@shipaddicted try y.FindElement({Type:"Edit", not:{Value:""}}).SetFocus() (if SetFocus() doesn't work, try Select() instead).
I guess this one wasn't one of the 683 ways I thought of to try this . . . :facepalm: :facepalm:

Thank you!
redrum
Posts: 100
Joined: 25 Jan 2015, 22:57

Re: UIA v2

24 May 2024, 12:06

I'm trying to grab a new notification (that is still on screen). Here's what UIA Viewer shows:
Screenshot 2024-05-24 123343.png
Screenshot 2024-05-24 123343.png (69.2 KiB) Viewed 231 times
Code from UIA Viewer's macro creator:

Code: Select all

ShellExperienceHostEl := UIA.ElementFromHandle("New notification ahk_exe ShellExperienceHost.exe")
ShellExperienceHostEl.ElementFromPath("").Highlight()
When I test the code:
Error: No matching window found
---- D:\Documents\AutoHotKey\AHK v2\Lib\UIA-v2-main\Lib\~UIAViewerMacro.tmp
▶ 003: ShellExperienceHostEl := UIA.ElementFromHandle("New notification ahk_exe ShellExperienceHost.exe")
004: ShellExperienceHostEl.ElementFromPath("").Highlight()
005: Exit
Same error if I try to grab child window "New notification from Snip & Sketch".
Descolada
Posts: 1188
Joined: 23 Dec 2021, 02:30

Re: UIA v2

24 May 2024, 13:13

@redrum internally ElementFromHandle uses WinExist to get the handle to the window and then calls IUIAutomation::ElementFromHandle with that handle to get the UIA element. If UIA.ElementFromHandle is throwing the error "No matching window found" then the WinExist call failed (so MsgBox WinExist("New notification ahk_exe ShellExperienceHost.exe") should display "0"). Why that is I can't say - are you sure the window is still on the screen and titled exactly that? Have you tried turning DetectHiddenWindows on?

Also I now see an oversight in UIAViewer macro creator: ShellExperienceHostEl.ElementFromPath("").Highlight() should actually be ShellExperienceHostEl.Highlight()
redrum
Posts: 100
Joined: 25 Jan 2015, 22:57

Re: UIA v2

24 May 2024, 15:05

MsgBox WinExist("New notification ahk_exe ShellExperienceHost.exe") does indeed return 0

WindowSpy:
New notification
ahk_class Windows.UI.Core.CoreWindow
ahk_exe ShellExperienceHost.exe
Window is definitely still on screen, and I tried with DetectHiddenWindows True.

I'll check if I can find if there's something special about these Windows toast notification windows.

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 20 guests