UIAViewer v2
Window Info:
ID 43845196,
Location {x:1159, y:234, w:256, h: 202},
ClassNN WindowsForms10.Window.808.app.0.e62666_r60_ad1,
Process Experior.exe
PID12964
Propèrties:
Type 50011 (MenuItem)
LocalizedType:"elemento de menú"
Name:"Mostrar Panel de Búsqueda"
Value:""
AutomationId:""
Location:{x:1161, y:386, w:252, h: 24}
ClassName:""
FullDescription:""
HelpText:""
AccessKey:""
AcceleratorKey:""
HasKeyboardFocus:0
IsKeyboardFocusable:1
ItemType:""
ProcessId:12964
IsEnabled:1
IsPassword:0
IsOffscreen:0
FrameworkId:""
IsRequiredForForm:0
ItemStatus:""
UIA v2
Re: UIA v2
is the dump of contextMenuElDescolada wrote: ↑22 Jan 2024, 06:11@buster25 as you can see the DumpAll doesn't contain an element named "Ajuste perfecto". Is it the DumpAll for npEl or for contextMenuEl?
In any case you somehow need to target the context menu window with ElementFromHandle. If "A" (or active window) didn't work, then perhaps you need to use contextMenuEl := UIA.ElementFromHandle(WinExist("ahk_exe Experior.exe",, "Asiento Inscripción: Inscripción")) instead.
Re: UIA v2
Succes ¡¡¡¡¡ thanks @DescoladaDescolada wrote: ↑22 Jan 2024, 06:11@buster25 as you can see the DumpAll doesn't contain an element named "Ajuste perfecto". Is it the DumpAll for npEl or for contextMenuEl?
In any case you somehow need to target the context menu window with ElementFromHandle. If "A" (or active window) didn't work, then perhaps you need to use contextMenuEl := UIA.ElementFromHandle(WinExist("ahk_exe Experior.exe",, "Asiento Inscripción: Inscripción")) instead.
Re: UIA v2
@Descolada
Hi man! You can help me with this?
I have:
try{
hello := pointer.FindElements({Name:"About this result", Type:"Button"})
}
if(hello.Length > 0){
for el in hello {
webPage := el.WalkTree("-1",{Type:"Link"})
The hello element is the red box, I find it, but webPage, just return the "Translate this page" element. Is there a filter that checks if the previous element has children?
Hi man! You can help me with this?
I have:
try{
hello := pointer.FindElements({Name:"About this result", Type:"Button"})
}
if(hello.Length > 0){
for el in hello {
webPage := el.WalkTree("-1",{Type:"Link"})
The hello element is the red box, I find it, but webPage, just return the "Translate this page" element. Is there a filter that checks if the previous element has children?
Re: UIA v2
@mora145 there isn't, but you can check the element for children with if Element.Children.Length and continue walking the tree if needed. Or if you know that you only need to skip "About this result" then perhaps el.WalkTree("-1", {Type:"Link", not:{Name:"About this result"}}) or el.WalkTree("-2", {Type:"Link"})
Re: UIA v2
el.WalkTree("-1", {Type:"Link", not:{Name:"Translate this page"}}) Really it can work for me, I was trying make el.WalkTree("-1",{Name:!"Translate this page", Type:"Link"})Descolada wrote: ↑26 Jan 2024, 01:48@mora145 there isn't, but you can check the element for children with if Element.Children.Length and continue walking the tree if needed. Or if you know that you only need to skip "About this result" then perhaps el.WalkTree("-1", {Type:"Link", not:{Name:"About this result"}}) or el.WalkTree("-2", {Type:"Link"})
Ty @Descolada
Re: UIA v2
Hello @Descolada, can you help me? Clicking on the "Zoom" button enables the "control deslizante", with a value of 144. I need to move that slider to another value, for example 124
This is my code:
This is my code:
Code: Select all
;#NoTrayIcon
#include C:\New Suite\FUSION 3.0 GREDOS\Lib\UIA.ahk
SetTitleMatchMode 1
WinActivate "Asiento Inscripción: Inscripción"
ZoomEl := UIA.ElementFromHandle(WinExist("ahk_exe Experior.exe",, "Asiento Inscripción: Inscripción"))
ZoomEl.WaitElement({Type:"Button", LocalizedType:"botón", Name:"Zoom: 144"})
ZoomEl_boton := ZoomEl.FindElement({Type:"Button", LocalizedType:"botón", Name:"Zoom: 144"}).Click()
ZoomEl.WaitElement({Type:"Slider", LocalizedType:"control deslizante", Name:"Control de Edición"})
ZoomEl_valor := ZoomEl.FindElement({Type:"Slider", LocalizedType:"control deslizante", Name:"Control de Edición"})
ZoomEl_valor.Value := "68"
ExitApp
- Attachments
-
- Slider.JPG (120.12 KiB) Viewed 1479 times
-
- BotonZoom.JPG (105.47 KiB) Viewed 1479 times
Re: UIA v2
A List hosts several ListItems, would it be possible to reveal the current ListItem in the List 's dump information?
Type: 50008 (List) LocalizedType: "列表"
1: Type: 50007 (ListItem) LocalizedType: "列表项目"
1,1: Type: 50020 (Text) Name: "1" LocalizedType: "文本"
2: Type: 50007 (ListItem) LocalizedType: "列表项目"
2,1: Type: 50020 (Text) Name: "2" LocalizedType: "文本"
3: Type: 50007 (ListItem) LocalizedType: "列表项目"
3,1: Type: 50020 (Text) Name: "3" LocalizedType: "文本"
4: Type: 50007 (ListItem) LocalizedType: "列表项目"
4,1: Type: 50020 (Text) Name: "4" LocalizedType: "文本"
5: Type: 50007 (ListItem) LocalizedType: "列表项目"
5,1: Type: 50020 (Text) Name: "5" LocalizedType: "文本"
6: Type: 50007 (ListItem) LocalizedType: "列表项目"
6,1: Type: 50020 (Text) Name: "6" LocalizedType: "文本"
7: Type: 50007 (ListItem) LocalizedType: "列表项目"
7,1: Type: 50020 (Text) Name: "" LocalizedType: "文本"
Type: 50008 (List) LocalizedType: "列表"
1: Type: 50007 (ListItem) LocalizedType: "列表项目"
1,1: Type: 50020 (Text) Name: "1" LocalizedType: "文本"
2: Type: 50007 (ListItem) LocalizedType: "列表项目"
2,1: Type: 50020 (Text) Name: "2" LocalizedType: "文本"
3: Type: 50007 (ListItem) LocalizedType: "列表项目"
3,1: Type: 50020 (Text) Name: "3" LocalizedType: "文本"
4: Type: 50007 (ListItem) LocalizedType: "列表项目"
4,1: Type: 50020 (Text) Name: "4" LocalizedType: "文本"
5: Type: 50007 (ListItem) LocalizedType: "列表项目"
5,1: Type: 50020 (Text) Name: "5" LocalizedType: "文本"
6: Type: 50007 (ListItem) LocalizedType: "列表项目"
6,1: Type: 50020 (Text) Name: "6" LocalizedType: "文本"
7: Type: 50007 (ListItem) LocalizedType: "列表项目"
7,1: Type: 50020 (Text) Name: "" LocalizedType: "文本"
- Attachments
-
- listb.png (36.46 KiB) Viewed 1506 times
-
- lista.png (37.45 KiB) Viewed 1506 times
-
- Posts: 78
- Joined: 06 May 2017, 11:07
Re: UIA v2
@Descolada do you know why several pages in a website, like this one, can't be found by UIA? I get this message:
This happens sometimes with this and other news websites, but most pages work well.Error: No matching window found
---- E:\pgm\AHK\func_v2.ahk
500: }
503: {
▶ 504: Return UIA.ElementFromHandle(WinGetTitle("A"))
505: }
---- E:\pgm\AHK\Lib\Misc.ahk
030: Range
The current thread will exit.
Re: UIA v2
@elbitjusticiero it probably depends on what your title match mode is set to in AHK, because WinGetTitle will return the full title for the active window, and then ElementFromHandle will internally call WinExist(window title) which appears to be failing. Just use UIA.ElementFromHandle("A") instead, or
Code: Select all
if hWnd := WinExist("A")
return UIA.ElementFromHandle(hWnd)
-
- Posts: 78
- Joined: 06 May 2017, 11:07
Re: UIA v2
Got it, thank you! UIA.ElementFromHandle("A") solved the problem.
My match mode is RegEx and I see the title includes a question mark. Hmmm.
My match mode is RegEx and I see the title includes a question mark. Hmmm.
Re: UIA v2
Hi @Descolada
How I can avoid the error: failed to find the browser!? I have a lot of this
How I can avoid the error: failed to find the browser!? I have a lot of this
Re: UIA v2
@Descolada Hi.
I am using UIA to do stuff in an app, which removes the focus from the element it was before. I was thinking I could use UIA.GetFocusedElement() to find out the focused element and when done doing stuff, to give the focus back to the element that had it before.
But the method throws an error: .
What can i do?
Thanks and Greets Spitzi
I am using UIA to do stuff in an app, which removes the focus from the element it was before. I was thinking I could use UIA.GetFocusedElement() to find out the focused element and when done doing stuff, to give the focus back to the element that had it before.
But the method throws an error: .
What can i do?
Thanks and Greets Spitzi
Re: UIA v2
@Spitzi the error message corresponds to UIA.GetFocusedElementBuildCache() or UIA.GetFocusedElement(cacheRequest), not UIA.GetFocusedElement(). Are you sure your cache request is valid?
-
- Posts: 43
- Joined: 24 Jul 2023, 04:34
Re: UIA v2
Hi @Descolada ,
Good day! Thank you for the awesome script! I use it a little and learning more each day as a noob. I have a question or two. Please answer at your convenience.
1. I want to select a tab on name but I have plenty with same name, want to select the latest one or last one opened. How do I go about it?
2. Is there a way to run a URL without bring it to focus or open in browser? I know there are alternatives like wget or curl but I want to use browser's session so would like to invoke the browser in non intrusive or invisible manner. Is this possible?
Good day! Thank you for the awesome script! I use it a little and learning more each day as a noob. I have a question or two. Please answer at your convenience.
1. I want to select a tab on name but I have plenty with same name, want to select the latest one or last one opened. How do I go about it?
2. Is there a way to run a URL without bring it to focus or open in browser? I know there are alternatives like wget or curl but I want to use browser's session so would like to invoke the browser in non intrusive or invisible manner. Is this possible?
Re: UIA v2
@reddyshyam
1. You can use the same search condition as with selecting a tab, but using index:-1 to get the last matching element. The exact code is browser-dependant, so if you want an example then UIA_Browser.ahk implements SelectTab and GetTabs (you could use cUIA.GetTabs("Tab name")[-1].Click() to select the last one).
2. I haven't needed that so I don't have an exact answer, but you could try hiding the browser when you launch the URL and make it visible afterwards. A more advanced version involves using SetWindowsHookEx with a dll that prevents window activation. The following example requires CBTProc_PreventActivate.dll (from the attached zip file) in the same folder as the script, and prevents Chrome from being activated when a new tab is launched:
Source code of the dll:
1. You can use the same search condition as with selecting a tab, but using index:-1 to get the last matching element. The exact code is browser-dependant, so if you want an example then UIA_Browser.ahk implements SelectTab and GetTabs (you could use cUIA.GetTabs("Tab name")[-1].Click() to select the last one).
2. I haven't needed that so I don't have an exact answer, but you could try hiding the browser when you launch the URL and make it visible afterwards. A more advanced version involves using SetWindowsHookEx with a dll that prevents window activation. The following example requires CBTProc_PreventActivate.dll (from the attached zip file) in the same folder as the script, and prevents Chrome from being activated when a new tab is launched:
Code: Select all
#Requires AutoHotkey v2
hWnd := WinExist("ahk_exe chrome.exe")
hLib := DllCall("LoadLibraryW", "str", A_ScriptDir "\CBTProc_PreventActivate.dll", "ptr")
pCBTProc := DllCall("GetProcAddress", "ptr", hLib, "astr", "CBTProc", "ptr")
threadId := DllCall("GetWindowThreadProcessId", "Ptr", hWnd, "Ptr", 0, "UInt")
hHook := DllCall("SetWindowsHookEx", "Int", WH_CBT := 5, "Ptr", pCBTProc, "Ptr", hLib, "UInt", threadId, "Ptr")
Run "chrome.exe www.google.com"
MsgBox "Chrome tab has been silently opened"
DllCall("UnhookWindowsHookEx", "Ptr", hHook)
Code: Select all
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
extern "C" __declspec(dllexport) LRESULT CALLBACK CBTProc(
_In_ int nCode,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
if (nCode < 0) return CallNextHookEx(nullptr, nCode, wParam, lParam);
switch (nCode)
{
case HCBT_ACTIVATE:
return 1; // Prevent
}
return CallNextHookEx(nullptr, nCode, wParam, lParam);
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
- Attachments
-
- CBTProc_PreventActivate.zip
- (4.59 KiB) Downloaded 174 times
-
- Posts: 43
- Joined: 24 Jul 2023, 04:34
Re: UIA v2
Hi @Descolada ,
Thanks for the prompt reply. Solution to question 1 looks like working, thank you.
Regarding second question, I want to be able to select elements of the invisible browser call just like we do via UIA browser script. I use Brave browser, the idea is not to interrupt my browsing and still check something on a URL like updates on a webpage, etc... In the above DLL hook example, I do not see cUIA := UIA_Browser("ahk_exe brave.exe") call so asking this question. I would like to check element on that page as shown below on a invisible call.
cUIA.ElementExist({Type:"Text", Name:"FULFILLED", matchmode:"Substring"}
Will this be possible?
Thanks for the prompt reply. Solution to question 1 looks like working, thank you.
Regarding second question, I want to be able to select elements of the invisible browser call just like we do via UIA browser script. I use Brave browser, the idea is not to interrupt my browsing and still check something on a URL like updates on a webpage, etc... In the above DLL hook example, I do not see cUIA := UIA_Browser("ahk_exe brave.exe") call so asking this question. I would like to check element on that page as shown below on a invisible call.
cUIA.ElementExist({Type:"Text", Name:"FULFILLED", matchmode:"Substring"}
Will this be possible?
Re: UIA v2
Hi @Descolada I was using
The call without the cacheRequest does not generate an error:
In my code, i want to scroll down on a window - which gives the focus to the scrollbar of that window. So I thought something like this migt work:
But it does not work. Do you have a suggestion how to solve this? Is it possible to scroll the scrollbar without giving it the focus?
Greets and Thanks once more. Spitzi
Code: Select all
focusedEl := UIA.GetFocusedElement(cacheRequest := 0)
Code: Select all
focusedEl := UIA.GetFocusedElement()
Code: Select all
focusedEl := UIA.GetFocusedElement() ; idea was to get the focused element and after scrolling give the focus back
scrollbarEl := befundWinEl.FindElement({Type:"ScrollBar"})
scrollbarEl.SetValue(scrollbarEl.Maximum) ; this will activate the scrollbar.
focusedEl.SetFocus()
Greets and Thanks once more. Spitzi
Re: UIA v2
@reddyshyam generally it's not possible, because Chromium-based apps (like Brave) require the window to be at least partially visible for UIAutomation to work. This means you can't use UIA to read contents from a non-selected tab, nor a minimized window, nor a window completely obscured by another windows. There are workarounds for the last case, eg hiding the window, bringing it to front, and then sending the window back again, but it isn't 100% reliable. I'd recommend going the Chrome.ahk or Rufaydium approach, as they can be used to automate the browser more reliably and in the background.
@Spitzi if the group element that owns the scrollbar (eg a listbox, treeview etc) implements the ScrollPattern (or perhaps the scrollbar itself implements it), then you can use its SetScrollPercent method to scroll. See Example11_ScrollPatternScrollItemPattern.ahk in the Examples folder. If it does, then it shouldn't necessarily focus the element (you can additionally try UIA.AutoSetFocus := False to disable UIA automatically focusing elements before doing actions).
@Spitzi if the group element that owns the scrollbar (eg a listbox, treeview etc) implements the ScrollPattern (or perhaps the scrollbar itself implements it), then you can use its SetScrollPercent method to scroll. See Example11_ScrollPatternScrollItemPattern.ahk in the Examples folder. If it does, then it shouldn't necessarily focus the element (you can additionally try UIA.AutoSetFocus := False to disable UIA automatically focusing elements before doing actions).
Re: UIA v2
@Descolada Thanks for the tip.
UIA.AutoSetFocus := false works nicely. The scrollbar does not get the focus while scrolling.
Ist it possible that a .Click() method or an .Invoke() does not go through when AutoSetFocus is set to false?
Greets Spitzi
UIA.AutoSetFocus := false works nicely. The scrollbar does not get the focus while scrolling.
Ist it possible that a .Click() method or an .Invoke() does not go through when AutoSetFocus is set to false?
Greets Spitzi
Return to “Scripts and Functions (v2)”
Who is online
Users browsing this forum: kunkel321 and 24 guests