Help with UIA login

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Help with UIA login

16 Feb 2023, 09:59

I made a YouTube app with MS Edge and a script that will open the app, but won't continue to interact with the elements. The only way to do so is to switch to make editor in order to refresh the script, then the hotkey you will make YouTube active and continue with the elements. I keep getting an error with line 11 where I had tried YouTube ahk_exe msedge.exe and msedge.exe:

Code: Select all

#SingleInstance Force
#Requires AutoHotkey v2.0.2
#NoTrayIcon
#Include <UIA-v2>
#Include <UIA_Browser-v2>
#HotIf
q::
{
If WinExist("YouTube ahk_exe msedge.exe")
WinActivate()
Else runApp("YouTube")

runApp(appName) {
For app in ComObject("Shell.Application").NameSpace("shell:AppsFolder").Items
Run(app.Name = appName ? "explorer shell:appsFolder\" app.Path : "")
}

; Get the element for the YouTube window
ytEl := UIA.ElementFromHandle("ahk_exe msedge.exe")
; Wait for the button by name and type, then click it
ytEl.WaitElement({Name:"Sign in", Type:"Link"}).Click()
; Enter email and password
ytEl.WaitElement({Name:"Email or phone", Type:"Edit"}).Value := "EMAIL ADDRESS"
ytEl.FindElement({Name:"Next", Type:"Button"}).Click()

}

Can you also tell me what's wrong with my DumpAll():

Code: Select all

q::
{
El := UIA.ElementFromHandle("scite.exe")
El.FindElement("Type=Toolbar")
MsgBox(A_Clipboard := El.DumpAll())
}
Descolada
Posts: 1172
Joined: 23 Dec 2021, 02:30

Re: Help with UIA login

16 Feb 2023, 15:11

Your YouTube code works fine, no errors at line 11. Are you completely sure you are running it in AHK v2?
Also don't automate the YouTube login page, you will get blocked from logging in with that particular browser (I am speaking from experience...).

And your DumpAll code should throw multiple errors in AHK v2:
1) El := UIA.ElementFromHandle("scite.exe") will throw a "window not found" error, because it should be "ahk_exe scite.exe"
2) El.FindElement("Type=Toolbar") throws an error that it requires an object for the condition argument: {Type:"ToolBar"} is correct.
Again, I think you are accidentally running AHK v1.
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Help with UIA login

16 Feb 2023, 18:31

I double checked and am sure that I'm using AHK v2. Now the DumpAll Renders this message: (9) : ==> This line does not contain a recognized action.
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Help with UIA login

07 Mar 2023, 16:46

Hello

I have a new login script where I get this error This variable appears to never be assigned a value. because the value has tAllwo periods in it, like 1111.1.1111
Descolada
Posts: 1172
Joined: 23 Dec 2021, 02:30

Re: Help with UIA login

07 Mar 2023, 16:51

@LAPIII, post your script, otherwise we can't help you. :)
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Help with UIA login

07 Mar 2023, 16:56

I can't show you the URL because it is a government site:

Code: Select all

#SingleInstance Force
#Requires AutoHotkey v2.0.2
#NoTrayIcon
#Include <UIA_Interface-v2>
#Include <UIA_Browser-v2>

If WinExist("ahk_exe msedge.exe")
WinActivate()
Else Run("msedge.exe")
WinWaitActive "ahk_exe msedge.exe"
cUIA := UIA_Browser()
Run("URL")
dUIA.WaitElement({Type:"Edit", Name:"Username"}).Value := l.a.p
cUIA.FindElement({Type:"Edit", Name:"Password"}).Value := PASSWORD
cUIA.FindElement({Type:"Button", Name:"Login"}).Click()
Descolada
Posts: 1172
Joined: 23 Dec 2021, 02:30

Re: Help with UIA login

08 Mar 2023, 00:15

Code: Select all

dUIA.WaitElement({Type:"Edit", Name:"Username"}).Value := l.a.p
cUIA.FindElement({Type:"Edit", Name:"Password"}).Value := PASSWORD
As far as I can see, you have not defined dUIA - did you mean cUIA? Also if you are assigning values, then they need to be numbers or strings, so l.a.p isn't valid, it should be "l.a.p". Same for PASSWORD, unless it's a variable you have defined somewhere else...
LAPIII
Posts: 669
Joined: 01 Aug 2021, 06:01

Re: Help with UIA login

08 Mar 2023, 07:20

Thank you. I put the values between quotation marks and changed all the cUIA to dUIA. I have trouble with a login, on eBay, that might require verification by selecting pictures. The first "verification" element that can appear, after I put in my username and click continue, is a checkbox. The first element on the password page that is different than on the previous page is the word Welcome, the url is the same.

Code: Select all

#SingleInstance Force
#Requires AutoHotkey v2.0.2
#NoTrayIcon
#Include <UIA_Interface-v2>
#Include <UIA_Browser-v2>

If WinExist("ahk_exe msedge.exe")
WinActivate()
Else Run("msedge.exe")
WinWaitActive "ahk_exe msedge.exe"
eUIA := UIA_Browser()
Run("https://signin.ebay.com/signin/")
eUIA.WaitElement({Type:"Edit", Name:"Email or username"}).Value := "username"
eUIA.FindElement({Type:"Button", Name: "Continue"}).Click()

Can I write if the password page doesn't appear, find that checkbox, then wait for my input? Perhaps it can even be looking for an element to continue logging in.

EDIT: If edge doesn't exist then why does it open a new tab when I run a script?

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Draken and 66 guests