UIAutomation with a focus on Chrome

Post your working scripts, libraries and tools for AHK v1.1 and older
leosouza85
Posts: 90
Joined: 22 Jul 2016, 16:28

Re: UIAutomation with a focus on Chrome

26 Jul 2022, 23:07

@Descolada
I don't know if this is intended but when I download the zip package from your github, and extract, the files are with the following encoding:

UIA_Interface.ahk - UTF-8 with BOM
UIA_Constants.ahk - UTF-8
UIA_Browser.ahk - UTF-8 with BOM
UIAViewer.ahk - UTF-8
UIATreeInspector.ahk - UTF-8 with BOM

Do you think this can cause some issues?!
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: UIAutomation with a focus on Chrome

27 Jul 2022, 07:54

@leosouza85, thanks for notifying! This is fixed now (and yes, potentially could cause problems).
eggsterino
Posts: 1
Joined: 28 Jul 2022, 00:45

Re: UIAutomation with a focus on Chrome

28 Jul 2022, 00:48

Thank you @Descolada for your great tool
When I double click UIAViewer.ahk I get the following message:
image.png
image.png (22.06 KiB) Viewed 4076 times
Are there any dependencies that I need to install?
User avatar
gregster
Posts: 9224
Joined: 30 Sep 2013, 06:48

Re: UIAutomation with a focus on Chrome

28 Jul 2022, 00:53

eggsterino wrote:
28 Jul 2022, 00:48

Are there any dependencies that I need to install?
Force-local mode was introduced a while ago, in AHK v1.1.27.
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: UIAutomation with a focus on Chrome

28 Jul 2022, 14:03

@eggsterino, as user gregster mentioned, the issue isn't a dependency but that your AHK version is old, so you might be better off updating your AHK. But since the line causing the error wasn't strictly necessary, I removed it and updated the UIAViewer.ahk in GitHub: you could try if it works now.
mora145
Posts: 57
Joined: 25 Jun 2022, 15:31

Re: UIAutomation with a focus on Chrome

29 Jul 2022, 00:53

Thank you!
Loop
Posts: 171
Joined: 07 Jan 2019, 14:51

Re: UIAutomation with a focus on Chrome

29 Jul 2022, 14:44

Hi, @Descolada
in the first post is one letter "t" too much, UIA_Element.Hightlight(displayTime:=2000, color:="Red", d:=4)

I have a ComboBox on a web page, I can set the value cUIA.FindFirstByType("ComboBox").SetValue("Test123"), but as soon as I click send button, I get the message that the field is empty. can I dispatch this without javascript?
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: UIAutomation with a focus on Chrome

29 Jul 2022, 23:08

Loop wrote:
29 Jul 2022, 14:44
Hi, @Descolada
in the first post is one letter "t" too much, UIA_Element.Hightlight(displayTime:=2000, color:="Red", d:=4)
Thanks, fixed.
I have a ComboBox on a web page, I can set the value cUIA.FindFirstByType("ComboBox").SetValue("Test123"), but as soon as I click send button, I get the message that the field is empty. can I dispatch this without javascript?
I've encountered the same problem. It seems that even though ValuePattern is available for comboboxes, setting the value doesn't actually *select* a combobox list item. I haven't tested it with comboboxes which support inserting custom values. So far I've gotten around this problem by using cUIA.FindFirstByType("ComboBox").ExpandCollapsePattern.Expand() and then cUIA.WaitElementExistByNameAndType("Test123", "ListItem").Click(). Alternatively you could use cUIA.FindFirstByType("ComboBox").SetFocus() and then Send or ControlSend: this should also work if the combobox allows you to insert custom values as well (not just select list items).
mora145
Posts: 57
Joined: 25 Jun 2022, 15:31

Re: UIAutomation with a focus on Chrome

30 Jul 2022, 14:13

Hello @Descolada . Taking advantage that you are online.
I am using an element search by Name and ControlType, but using a variable for Name. Where LanguagueTarget is the variable.
Does the library accept variable names?

Code: Select all

cEl.FindFirstBy("NAME=%LanguagueTarget% AND ControlType=Button").Click("left")
Last edited by mora145 on 31 Jul 2022, 00:28, edited 1 time in total.
leosouza85
Posts: 90
Joined: 22 Jul 2016, 16:28

Re: UIAutomation with a focus on Chrome

30 Jul 2022, 18:43

@Descolada

Thank you again for all your work! I think that would be interesting a button that copy all the content of the constructed tree on UIA Viewer and Tree Inspector... or there is a way that I not saw?
leosouza85
Posts: 90
Joined: 22 Jul 2016, 16:28

Re: UIAutomation with a focus on Chrome

30 Jul 2022, 23:02

Code: Select all

caixadialogo := cUIA.FindFirstByType("Custom")
msgbox % caixadialogo.DumpAll()
texto := caixadialogo.FindAllByType("Text")
msgbox % texto.DumpAll()
the first msgbox shows a lot of elements including of the ControlType text, but the second msgbox is empty...but it should be showing all text elements from the other variable right?

what I'm doing wrong?

Edit: If I use findfirstbyname or findfirstbytype it works for finding the first element. but findall is finding nothing
Last edited by leosouza85 on 31 Jul 2022, 00:05, edited 2 times in total.
Descolada
Posts: 1431
Joined: 23 Dec 2021, 02:30

Re: UIAutomation with a focus on Chrome

30 Jul 2022, 23:13

@leosouza85, currently there isn't a way to copy the whole constructed tree to clipboard, simply because I haven't found a need for it so far :D As an alternative you can use DumpAll to do that instead, and if it doesn't contain enough properties for your liking then you could easily modify the Dump method to add additional properties (e.g. BoundingRectangle). Do you have an example where copying the whole tree would be useful?

In the code you provided, in the first case FindFirst returns an element, and since DumpAll is a method for element objects, it works. In the second case the FindAll returns an element ARRAY, which isn't an element object. So you need to loop over the array and Dump the individual elements: texto[1].Dump() would Dump the first found element for example.
leosouza85
Posts: 90
Joined: 22 Jul 2016, 16:28

Re: UIAutomation with a focus on Chrome

30 Jul 2022, 23:47

Descolada wrote:
30 Jul 2022, 23:13
@leosouza85, currently there isn't a way to copy the whole constructed tree to clipboard, simply because I haven't found a need for it so far :D As an alternative you can use DumpAll to do that instead, and if it doesn't contain enough properties for your liking then you could easily modify the Dump method to add additional properties (e.g. BoundingRectangle). Do you have an example where copying the whole tree would be useful?

In the code you provided, in the first case FindFirst returns an element, and since DumpAll is a method for element objects, it works. In the second case the FindAll returns an element ARRAY, which isn't an element object. So you need to loop over the array and Dump the individual elements: texto[1].Dump() would Dump the first found element for example.
Thank You for the explanation! The use case for copying the constructed tree is to paste it somewhere to search for the terms more confortably, without the need to write a script for that.


@Descolada I've never seen anybody using the following syntax:

Code: Select all

caixadialogo := cUIA.FindFirstByType("Custom").FindFirstByName("Recebido",,2)
It finds a element inside a element on one line of code... maybe it will help some people.
Last edited by leosouza85 on 31 Jul 2022, 13:43, edited 1 time in total.
mora145
Posts: 57
Joined: 25 Jun 2022, 15:31

Re: UIAutomation with a focus on Chrome

31 Jul 2022, 13:23

mora145 wrote:
30 Jul 2022, 14:13
Hello @Descolada . Taking advantage that you are online.
I am using an element search by Name and ControlType, but using a variable for Name. Where LanguagueTarget is the variable.
Does the library accept variable names?

Code: Select all

cEl.FindFirstBy("NAME=%LanguagueTarget% AND ControlType=Button").Click("left")
Hi @Descolada , Have you been able to see this?
(Excuse my English, I speak native Spanish).
leosouza85
Posts: 90
Joined: 22 Jul 2016, 16:28

Re: UIAutomation with a focus on Chrome

31 Jul 2022, 13:42

mora145 wrote:
31 Jul 2022, 13:23
mora145 wrote:
30 Jul 2022, 14:13
Hello @Descolada . Taking advantage that you are online.
I am using an element search by Name and ControlType, but using a variable for Name. Where LanguagueTarget is the variable.
Does the library accept variable names?

Code: Select all

cEl.FindFirstBy("NAME=%LanguagueTarget% AND ControlType=Button").Click("left")
Hi @Descolada , Have you been able to see this?
(Excuse my English, I speak native Spanish).
Hi, I'm not descolada but I think I can help you...

Try that way:

Code: Select all

cEl.FindFirstBy("NAME=" LanguagueTarget  " AND ControlType=Button").Click("left")
mora145
Posts: 57
Joined: 25 Jun 2022, 15:31

Re: UIAutomation with a focus on Chrome

31 Jul 2022, 13:44

leosouza85 wrote:
31 Jul 2022, 13:42
mora145 wrote:
31 Jul 2022, 13:23
mora145 wrote:
30 Jul 2022, 14:13
Hello @Descolada . Taking advantage that you are online.
I am using an element search by Name and ControlType, but using a variable for Name. Where LanguagueTarget is the variable.
Does the library accept variable names?

Code: Select all

cEl.FindFirstBy("NAME=%LanguagueTarget% AND ControlType=Button").Click("left")
Hi @Descolada , Have you been able to see this?
(Excuse my English, I speak native Spanish).
Hi, I'm not descolada but I think I can help you...

Try that way:

Code: Select all

cEl.FindFirstBy("NAME=" LanguagueTarget  " AND ControlType=Button").Click("left")
Ty. I have tried using syntaxys like that, but the libs read the string as a full string :(
leosouza85
Posts: 90
Joined: 22 Jul 2016, 16:28

Re: UIAutomation with a focus on Chrome

31 Jul 2022, 13:49

mora145 wrote:
31 Jul 2022, 13:44
leosouza85 wrote:
31 Jul 2022, 13:42
mora145 wrote:
31 Jul 2022, 13:23
mora145 wrote:
30 Jul 2022, 14:13
Hello @Descolada . Taking advantage that you are online.
I am using an element search by Name and ControlType, but using a variable for Name. Where LanguagueTarget is the variable.
Does the library accept variable names?

Code: Select all

cEl.FindFirstBy("NAME=%LanguagueTarget% AND ControlType=Button").Click("left")
Hi @Descolada , Have you been able to see this?
(Excuse my English, I speak native Spanish).
Hi, I'm not descolada but I think I can help you...

Try that way:

Code: Select all

cEl.FindFirstBy("NAME=" LanguagueTarget  " AND ControlType=Button").Click("left")
Ty. I have tried using syntaxys like that, but the libs read the string as a full string :(
But I've tested here and it worked

Can you paste the exact code that you tested in this syntax and didn't work?

for example, this code clicks on post reply here on the forum:

Code: Select all

test := "Post Reply"
browserExe := "chrome.exe"
WinActivate, ahk_exe %browserExe%
WinWaitActive, ahk_exe %browserExe%
sleep 500
cUIA := new UIA_Browser("ahk_exe " browserExe)
cUIA.FindFirstBy("Name=" test " AND Controltype=Hyperlink").Click()
return
make sure you have isolated the parts of the strings in double quotes, spaces on the variable beggining and ending and a space btween double quotes and AND
Last edited by leosouza85 on 31 Jul 2022, 13:51, edited 1 time in total.
mora145
Posts: 57
Joined: 25 Jun 2022, 15:31

Re: UIAutomation with a focus on Chrome

31 Jul 2022, 13:50

FAIL DUPLICATED
Last edited by mora145 on 31 Jul 2022, 14:05, edited 1 time in total.
leosouza85
Posts: 90
Joined: 22 Jul 2016, 16:28

Re: UIAutomation with a focus on Chrome

31 Jul 2022, 13:53

mora145 wrote:
31 Jul 2022, 13:50
leosouza85 wrote:
31 Jul 2022, 13:42
mora145 wrote:
31 Jul 2022, 13:23
mora145 wrote:
30 Jul 2022, 14:13
Hello @Descolada . Taking advantage that you are online.
I am using an element search by Name and ControlType, but using a variable for Name. Where LanguagueTarget is the variable.
Does the library accept variable names?

Code: Select all

cEl.FindFirstBy("NAME=%LanguagueTarget% AND ControlType=Button").Click("left")
Hi @Descolada , Have you been able to see this?
(Excuse my English, I speak native Spanish).
Hi, I'm not descolada but I think I can help you...

Try that way:

Code: Select all

cEl.FindFirstBy("NAME=" LanguagueTarget  " AND ControlType=Button").Click("left")
Ty. I have tried using syntaxys like that, but the libs read the string as a full string :(
Your post duplicated, I did some clarification on the post before this.
mora145
Posts: 57
Joined: 25 Jun 2022, 15:31

Re: UIAutomation with a focus on Chrome

31 Jul 2022, 13:55

Ty. I have tried using syntaxys like that, but the libs read the string as a full string :(

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 135 guests