UIA_Browser login Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LAPIII
Posts: 667
Joined: 01 Aug 2021, 06:01

UIA_Browser login

Post by LAPIII » 26 Jan 2023, 15:16

I want to log in at https://www.foxit.com/login/ and I want to enter text into the control with the Name: "Email Address:*" and ControlType: "edit":

Code: Select all

#NoEnv
#Warn
#SingleInstance force
SetTitleMatchMode, 2
#include <UIA_Interface>
#include <UIA_Browser>

browserExe := "msedge.exe"
Run, %browserExe% -incognito --force-renderer-accessibility
WinWaitActive, ahk_exe %browserExe%
cUIA := new UIA_Browser("ahk_exe " browserExe)
cUIA.Navigate("https://www.foxit.com/login/")
cUIA.WaitElementExistByName("Email Address:*")
cUIA.FindFirstByName("Email Address:*", "edit").Click()

return

william_ahk
Posts: 481
Joined: 03 Dec 2018, 20:02

Re: UIA_Browser login

Post by william_ahk » 26 Jan 2023, 23:06

FindFirstByName only accepts name, its second parameter is scope. You are looking for FindFirstByNameAndType or FindFirstBy.

Code: Select all

cUIA := new UIA_Browser("ahk_exe " browserExe)
cUIA.Navigate("https://www.foxit.com/login/")
cUIA.WaitElementExistByNameAndType("Email Address:*", "Edit").Value := "[email protected]"
cUIA.FindFirstByNameAndType("Password: *", "Edit").Value := "test1234"
cUIA.FindFirstByNameAndType("Log In", "Button").Click()

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

Re: UIA_Browser login

Post by LAPIII » 27 Jan 2023, 20:40

What if there is a URL Redirect, such as on Best Buyfor signing in? First you need to click Account and then Sign In.

william_ahk
Posts: 481
Joined: 03 Dec 2018, 20:02

Re: UIA_Browser login

Post by william_ahk » 27 Jan 2023, 22:22

Use WaitPageLoad or WaitElementExist or both

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

Re: UIA_Browser login

Post by LAPIII » 29 Jan 2023, 18:32

Why won't this tool work on Newegg (It's supposed to get all elements on the page and copy them to clipboard):

Code: Select all

#NoEnv
#Warn
#SingleInstance force
SetTitleMatchMode, 2
#include <UIA_Interface>
#include <UIA_Browser>

browserExe := "msedge.exe"

  if !WinExist("ahk_exe " browserExe)
        Run, %browserExe%
    else
        WinActivate, % "ahk_exe " browserExe
Send, ^t
    WinWaitActive, ahk_exe %browserExe%

cUIA := new UIA_Browser("ahk_exe " browserExe)
;cUIA.WaitPageLoad("New inprivate tab", 1000)
cUIA.Navigate("https://www.newegg.com/")
Clipboard=
Clipboard := cUIA.GetCurrentDocumentElement().DumpAll() ; Get the current document element (this excludes the URL bar, navigation buttons etc) and dump all the information about it in the clipboard. Use Ctrl+V to paste it somewhere, such as in Notepad.
ClipWait, 1
if Clipboard
	MsgBox, Page information successfully dumped. Use Ctrl+V to paste the info somewhere, such as in Notepad.
else
	MsgBox, Something went wrong and nothing was dumped in the clipboard!
ExitApp

Webpage_elements.ahk 27_01_23 04⦂15⦂20⦂714 PM.jpg
Webpage_elements.ahk 27_01_23 04⦂15⦂20⦂714 PM.jpg (103.33 KiB) Viewed 328 times

What's wrong here:

Code: Select all

#NoEnv
#Warn
#SingleInstance force
SetTitleMatchMode, 2
#include <UIA_Interface>
#include <UIA_Browser>

browserExe := "msedge.exe"
Run, %browserExe%
WinWaitActive, ahk_exe %browserExe%
cUIA := new UIA_Browser("ahk_exe " browserExe)
cUIA.Navigate("https://www.newegg.com/")
;cUIA.WaitElementExistByControlTypeandHelpText("Hyperlink", "My Account")
cUIA.FindFirstByControlTypeandHelpText("Hyperlink", "My Account").Click()
return

TEST_2.ahk 29_01_23 06⦂31⦂52⦂181 PM.jpg
TEST_2.ahk 29_01_23 06⦂31⦂52⦂181 PM.jpg (43.81 KiB) Viewed 329 times

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

Re: UIA_Browser login  Topic is solved

Post by Descolada » 30 Jan 2023, 00:30

@LAPIII, the second error is because the method FindFirstByControlTypeandHelpText doesn't exist. If you want to use anything other than Type or Name, you need to use FindFirstBy instead: FindFirstBy("Type=Hyperlink AND HelpText=My Account")

As to the first error, I'm not exactly sure why you would get it. I'll test it out later when I get time.

Post Reply

Return to “Ask for Help (v1)”