UIA If / Else help.

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

UIA If / Else help.

Post by LAPIII » 18 Oct 2023, 09:15

If I start an autologin, like so:

Code: Select all

#Requires Autohotkey v2.0+
#Include <UIA>
#Include <UIA_Browser>
Run "chrome.exe https://google.com"
WinWaitActive "ahk_exe chrome.exe"
cUIA := UIA_Browser()
cUIA.ElementFromHandle()

if (button := cUIA.ElementFromPathExist("VR0/")) && InStr(button.Name, "Google Account")
    button.Click() ; already logged in
else if (button := cUIA.ElementFromPathExist("VR5/")) && (button.Name == "Sign in")
    button.Click() ; click Sign in
How can I continue to choose my account? I can't just add to the end of the script cUIA.WaitElementFromPath("V875").Click() ; My account

Descolada
Posts: 1202
Joined: 23 Dec 2021, 02:30

Re: UIA If / Else help.

Post by Descolada » 18 Oct 2023, 11:04

You could add it to the end of the "else if", something like

Code: Select all

if (button := cUIA.ElementFromPathExist("VR0/")) && InStr(button.Name, "Google Account")
    button.Click() ; already logged in
else if (button := cUIA.ElementFromPathExist("VR5/")) && (button.Name == "Sign in") {
    button.Click() ; click Sign in
    Sleep 100
    cUIA.WaitPageLoad()
    cUIA.WaitElementFromPath("V875").Click() ; My account
}
WARNING: Google can detect UIA autologin attempts and will block your browser from logging in if you do it too much! I think automating getting to the Sign in page might not trigger their detection mechanisms, but after that I don't recommend autofilling anything with UIA on a Google login page.

LAPIII
Posts: 671
Joined: 01 Aug 2021, 06:01

Re: UIA If / Else help.

Post by LAPIII » 26 Oct 2023, 22:03

On Pinterest.com, when logged in I can't select "Log out" from the "Accounts and more options" button in the top right corner. This is what I was wanted to do in Chrome:

Code: Select all

Sleep(2500)
if button := cUIA.ElementFromPathExist("VR0/")
button.click(),
button.ElementFromPathExist("VRR9B/") && (button.Name == "Log out")
button.click()
else if (button := cUIA.ElementFromPathExist("VR0q")) && (button.Name == "Log in")
    button.click()  
cUIA.WaitElementFromPath("VRQQ4").Value := "EMAIL"
cUIA.WaitElementFromPath("VRQQ4/").Value := "PASSWORD"
cUIA.WaitElementFromPath("VRQQ0r").Click()
Last edited by LAPIII on 27 Oct 2023, 16:26, edited 5 times in total.

emp00
Posts: 165
Joined: 15 Apr 2023, 12:02

Re: UIA If / Else help.

Post by emp00 » 27 Oct 2023, 13:43

@LAPIII Wouldn't it be a lot easier and moreover much more secure if you just use your browser's password manager? In your above posted AHK script your login credentials are completely unprotected in a simple text file (not encrypted, nothing) - so anybody with access to your machine, locally or remotely, will get your credentials "for free". Just food for thought.

Post Reply

Return to “Ask for Help (v2)”