Re: UIAutomation with a focus on Chrome
Posted: 03 Sep 2022, 18:49
You are very welcome my friend.
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=104999
Code: Select all
pos := Element.GetCurrentPos()
MouseMouse, % pos.x + pos.w//2, % pos.y+pos.h//2
Code: Select all
AudioWalker := UIA.CreateTreeWalker(UIA.CreateCondition("ControlType=Button AND Name='Voicemail'"))
NextAudio := AudioWalker.GetNextSiblingElement(FirstAudio)
CurrPos := NextAudio.GetCurrentPos()
MouseMove, % CurrPos.x + CurrPos.w//2 , % CurrPos.y + CurrPos.h//2
Sleep, 1500
Click, % CurrPos.x + 280 " " CurrPos.y " left"
No, unfortunately not! The only distinguishing factor is ControlType=imageif the image is an element identifiable by UIA
Code: Select all
#include Lib\UIA_Interface.ahk
#include Lib\UIA_Browser.ahk
#SingleInstance Force
ch := new UIA_Browser("UIAutomation with a focus on Chrome - Page 16 - AutoHotkey Community - Google Chrome")
ch.WaitElementExistByName("Login").Click()
Code: Select all
#include <UIA_Interface>
UIA := UIA_Interface()
skypeEl := UIA.ElementFromChromium("ahk_exe skype.exe")
MsgBox, % skypeEl.DumpAll()
Code: Select all
#include <UIA_Interface>
UIA := UIA_Interface()
winEl := UIA.ElementFromHandle("ahk_exe skype.exe", skypeEl)
MsgBox, % winEl.DumpAll() ; will not show the content
MsgBox, % skypeEl.DumpAll() ; WILL show the content, but only on the first run (since UIA will be activated only once per run)
; The following will NOT work, since it would be ran for a second time. Use ElementFromChromium for multiple accesses
; winEl := UIA.ElementFromHandle("ahk_exe skype.exe", skypeEl)
; MsgBox, % skypeEl.DumpAll()
Wow congratulations!! You are the best ahk developer right now!Descolada wrote: ↑09 Sep 2022, 12:36I think I've had a breakthrough for the annoying problem of getting UIA access to Chromium windows such as Skype and Discord! The secret appears to be to get the Chrome_RenderWidgetHostHWND1 control and then use that hwnd to get the element! I've added a new method UIA_Interface.ElementFromChromium(winTitle="A", activateChromiumAccessibility=True), and made all other activateChromiumAccessibility flags (eg for ElementFromHandle) ByRef so they will also return that element on the first run.
Example:Example2:Code: Select all
#include <UIA_Interface> UIA := UIA_Interface() skypeEl := UIA.ElementFromChromium("ahk_exe skype.exe") MsgBox, % skypeEl.DumpAll()
Code: Select all
#include <UIA_Interface> UIA := UIA_Interface() winEl := UIA.ElementFromHandle("ahk_exe skype.exe", skypeEl) MsgBox, % winEl.DumpAll() ; will not show the content MsgBox, % skypeEl.DumpAll() ; WILL show the content, but only on the first run (since UIA will be activated only once per run) ; The following will NOT work, since it would be ran for a second time. Use ElementFromChromium for multiple accesses ; winEl := UIA.ElementFromHandle("ahk_exe skype.exe", skypeEl) ; MsgBox, % skypeEl.DumpAll()
My apologies, it was user error. Other topic, is there a way to limit how far down each node the tree builds when using UIA.ElementFromHandle? So for instance, if I print out the results using npEl.DumpAll(), there are a lot of sub-sub-sub nodes displayed. ANy way to limit how deep of these nodes gets built?Descolada wrote: ↑15 Sep 2022, 23:00@Skrell, it should be possible to use ANY window identifier you use with other AHK functions to also get UIA elements. That means ElementFromHandle("ahk_class Framework::CFrame") is valid, and even using control hwnds is valid (this can be gotten with ControlGet Hwnd and then used with "ahk_id ...").
I haven't played much with Office apps - is there any specific problem you are having trouble with?
Code: Select all
1 Type: 50033 (Pane) LocalizedControlType: "Pane" ClassName: "NetUIPanViewer"
1.1 Type: 50026 (Group) LocalizedControlType: "Group" ClassName: "NetUITWMenuItemGroup"
1.1.1 Type: 50011 (MenuItem) Name: "Copy" LocalizedControlType: "Menu Item" ClassName: "NetUITWBtnMenuItem"
1.1.2 Type: 50011 (MenuItem) Name: "Quick Print" LocalizedControlType: "Menu Item" ClassName: "NetUITWBtnMenuItem"
1.2 Type: 50026 (Group) LocalizedControlType: "Group" ClassName: "NetUITWMenuItemGroup"
1.2.1 Type: 50011 (MenuItem) Name: "Reply" LocalizedControlType: "Menu Item" ClassName: "NetUITWBtnMenuItem"
1.2.2 Type: 50011 (MenuItem) Name: "Reply All" LocalizedControlType: "Menu Item" ClassName: "NetUITWBtnMenuItem"
1.2.3 Type: 50011 (MenuItem) Name: "Forward" LocalizedControlType: "Menu Item" ClassName: "NetUITWBtnMenuItem"
Sorry, I wasn't clear, I want to speed up UIA.ElementFromHandle by having it build an element with only part of the tree by limiting its depth... is that a possibility?Descolada wrote: ↑16 Sep 2022, 10:36@Skrell, you can limit DumpAll with the maxDepth argument. el.DumpAll(0) will only "build" once layer, el.DumpAll(1) two layers etc. Though I just noticed this is weird notation (1 should show 1 layer...), so I just fixed this and el.DumpAll(1) will show one layer and el.DumpAll(0) the node itself (the updated UIA_Interface.ahk is in Github).
Got it ty!Descolada wrote: ↑16 Sep 2022, 12:44@Skrell, ElementFromHandle doesn't "build" anything, it only gets an element from an already existing UIA tree. Building the tree is handled by Microsoft UIAutomation library itself and the application. The only way to speed up ElementFromHandle is to set the "activateChromiumAccessibility" flag to False, which otherwise might cause slowdowns if the app is a Chromium app (Skype, VSCode etc) and doesn't require activating.
Code: Select all
<select name="pagamenti_table_length" aria-controls="pagamenti_table" class="custom-select custom-select-sm form-control form-control-sm">
<option value="10">10</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>