Auto-login problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Auto-login problem

06 Nov 2018, 13:25

Hello boys,

I'm kinda of struggling with this for a while now, and cannot find answer.
I'm using this to autologin on several websites, to facilitate my "starting of day" procedure.
Well, this is until this website comes up.
I cannot, for the life of me, understand how to keep data on the fields, because as soon as i tell it to click login button, the data disapears..
What am i doing wrong?

Code: Select all

		ie := ComObjCreate("InternetExplorer.Application")
		ie.Visible := True ; Make the IE object visible
		WinActivate,% "ahk_id " hwnd:=ie.Application.Hwnd
		ie.Navigate("support.hpe.com/hpesc/home/profile")
	IEWait(ie){
		while ie.busy || (ie.document && ie.document.readyState != "complete") || ie.readyState!=4
		Sleep 3000
	}
	IEWait(ie)
	IE.document.getElementById("username").Value := "WillTester"
		sleep 500
	IE.document.getElementById("password").Value := "Testing123*"
		sleep 500
	IE.document.getElementById("signIn").Click()
return
I just want it to login nothing more.

Created user to test the login, tested it and it logs in the website by hand..

Thanks in advance to any charitable soul that wants a small challenge :D
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

06 Nov 2018, 13:29

Update:

Fixed wrong tag ID...

And yeah, tags seem correct.

Username:
<input type="text" id="username" value="" placeholder="Your user ID may be your email" required="">

Password:
<input type="password" id="password" value="" required="">

Button:

<button id="signIn" type="submit" class="grommetux-button grommetux-button--primary grommetux-button--fill"><span class="grommetux-button__label">Sign in</span></button>
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Auto-login problem

07 Nov 2018, 07:44

Some "smart" login applets require raw data input, that is they need to "feel" that user has pushed the keys one by one.
I did it like this:

Code: Select all

addr := "[email protected]"
pass := "mypassword"
WinActivate, ahk_class MozillaWindowClass
WinWaitActive, ahk_class MozillaWindowClass
SendRaw %addr%
Send {Tab}
SendRaw %pass%
Send {Tab}
Send {Space}
Send {Tab}
Send {Enter}
Obviously, ahk_class should match the browser type (in my case Pale Moon but should work for Firefox too).
The Tabs and Spaces are necessary to navigate through certain extra options, finally reaching the Login button which receives an Enter.
The key is the use of SendRaw for this type of applets. And the first input field (assumingly Username/e-Mail) should first be focused by hand or through other means (like COMObject Click).
Part of my AHK work can be found here.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Auto-login problem

07 Nov 2018, 11:31

why is the data disappearing an issue? as long as its correct, it should log u right in.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Auto-login problem

07 Nov 2018, 11:50

Not necessarily. Those "smart" applets I mentioned above have some kind of protection, most likely designed specially to prevent automation. If they do not detect manual input, they invalidate the data, which results in login error. Whatever can be done to piss off (and on) users in the name of "security". :(
Part of my AHK work can be found here.
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

08 Nov 2018, 03:33

Hello Drugwash and Swagfag.
Thank you for your input.

@Drugwash: Well, the sending of keys is not a good idea on this one, as layout might change and the script would become unusable.
That's why im using IDs, as they will not change.

@Swagfag: Well, i have no idea, but as soon as script works, it resets both fields as soon as it goes for the button.
Might be somekind of protection, like Drugwash said, but im not getting through it easilly, and i cannot work out why it's doing it.
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

08 Nov 2018, 07:05

ok, fixed it...
I simply bypassed using IE.document.getElementById("whatever").Value and went straight for sending keys....

Code: Select all

	send, WillTester
		Sleep 500
	send, {Tab}
		Sleep 500
	send, Testing123*
		Sleep 500
	send, {Enter}

IEWait(ie)
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Auto-login problem

08 Nov 2018, 08:40

Portwolf wrote:
08 Nov 2018, 03:33
Thank you for your input.
@Drugwash: Well, the sending of keys is not a good idea on this one, as layout might change and the script would become unusable.
That's why im using IDs, as they will not change.
You're welcome.
Indeed, layout may change. I believe it's possible to combine DOM commands with sending keys. The trick is to get the proper fields focused at the right time through a manual-like command, such as Click or sending Tab. Getting the field IDs and then clicking them in the right order should ensure a proper operation of the script until IDs change.

A bummer is the two-step login which requires DOM commands to find out when new page has fully loaded after first step (username/e-mail) in order to send the password. I haven't gotten there yet, COM/DOM/objects/etc are "ugly" for me.

Funny how things get harder and harder for the user while easier for the bots.
Part of my AHK work can be found here.
shipaddicted
Posts: 89
Joined: 15 Jul 2016, 19:57

Re: Auto-login problem

10 Nov 2018, 12:21

I'm dealing with the same exact issue! I FINALLY, FINALLY got auto logins working on most of my sites, but I have a couple that are being stubborn. But thanks to this post, this is what I cobbled together:

Code: Select all

gosite := "https://ess.impellam.com/default.aspx"
GoSub, Nav
Sleep, 500
wb.Document.getElementbyId("ctl00_ctl00_main_content_menuCallbackPanel_actionButton_Login").click()
While wb.Busy ; wait for page to load
	Sleep, 100 ; 1/10 second
Sleep, 1000
UserNameInput := wb.document.getElementbyId("ctl00_ctl00_main_content_loginPopup_loginControl_username_I")
SendRaw %UN6%
Send, {Tab}
Sleep, 500
PasswordInput := wb.document.getElementbyId("ctl00_ctl00_main_content_loginPopup_loginControl_password_I")
SendRaw %PW2%
Sleep, 500
wb.Document.getElementbyId("ctl00_ctl00_main_content_loginPopup_loginControl_login_I").click()
Return 
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

10 Nov 2018, 16:03

@Drugwash:
Indeed.... This is my main worry right now, because im at a stage where i got the whole program working, and the annoying thing is that it will run on a hidden window. And there is a simple thing that will throw it in the trashbin. Losing focus on the window while sending keys will make the whole program useless. I now gotta find a way to call focus to a hidden window and send it keys..

@shipaddicted:nunofernandeshpcds
I couldn't do it like that, have no clue why..
I had to send the keys "manually".
And you unlocked it for me! Thank you!!

:P
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Auto-login problem

12 Nov 2018, 10:58

Portwolf wrote:
10 Nov 2018, 16:03
@Drugwash:
Indeed.... This is my main worry right now, because im at a stage where i got the whole program working, and the annoying thing is that it will run on a hidden window. And there is a simple thing that will throw it in the trashbin. Losing focus on the window while sending keys will make the whole program useless. I now gotta find a way to call focus to a hidden window and send it keys..
I don't think it's possible to focus a non-active window. :?
Part of my AHK work can be found here.
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

13 Nov 2018, 19:41

I read something about sending commands with the PID of the window. Is that a thing?
It should be possible to "call" the window to send the command...

Gonna search a bit more then.
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Auto-login problem

14 Nov 2018, 12:22

Calling a window, as you call it, means making it active and focused. AHK simply can't send a sequence of raw characters to a non-active non-focused window. And those damn things are made specially to deter automatisation.
Part of my AHK work can be found here.
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

14 Nov 2018, 18:44

How can i then login on a hidden IE webpage, created on a Com OBJ? I need it to be hidden, as i just want the GUI on the front, and i need to send keystrokes to it, because using ElementByID to send value just blanks out both password and username fields when it goes for the Login button..
User avatar
Drugwash
Posts: 850
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania
Contact:

Re: Auto-login problem

14 Nov 2018, 23:54

Image
Part of my AHK work can be found here.
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

20 Nov 2018, 07:47

Drugwash wrote:
14 Nov 2018, 23:54
Image
Got it :)

Code: Select all

		
				WinActivate , website_name, some_website_text


		ie.Document.getElementbyId("username").Click()
			SendRaw %User%
				sleep 500
		ie.Document.getElementbyId("password").Click()
			SendRaw %Pass%
				sleep 500
		ie.Document.getElementbyId("signIn").click()
		

		
	
This pretty much works with the window visible, will try now with it hidden...
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

02 Dec 2018, 20:42

Back to the problems...
So, im inserting the explorer in GUI, easier to visualize the tests...
But i cannot send data to a form.

Code: Select all

/*
SCMT V2


 */
 

 
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
SetBatchLines, -1
#SingleInstance Force
DetectHiddenWindows, On
 #include, includes\gui.ahk
 
 

Logfile = %A_ScriptDir%\logs\error_log.txt


 
 ; ****************************************************************************************
; *      FUNCTIONS
; ****************************************************************************************

countdown(){
   GuiControl,,WorkingStatus, Restarting tests in 5 seconds.
      Sleep 1000
   GuiControl,,WorkingStatus, Restarting tests in 4 seconds.
      Sleep 1000
   GuiControl,,WorkingStatus, Restarting tests in 3 seconds.
      Sleep 1000
   GuiControl,,WorkingStatus, Restarting tests in 2 seconds.
      Sleep 1000
   GuiControl,,WorkingStatus, Restarting tests in 1 seconds.
      Sleep 1000
   GuiControl,,WorkingStatus, Restarting tests Now.
      Sleep 1000
}

clearFields(){
   GuiControl,,WorkingStatus, Reseting fields..
   GuiControl,,HeaderStatus, ....
   GuiControl,,MenuStatus, ....
   GuiControl,,ContentStatus, ....
   GuiControl,,FooterStatus, ....
   GuiControl,,UsernameStatus, ....
   GuiControl,,PasswordStatus, ....
   GuiControl,,LoginValidator, ....
   GuiControl,,FirstHeaderStatus, ....
   GuiControl,,SecondHeaderStatus, ....
   GuiControl,,LoggedInProfileMenu, ....
   GuiControl,,LoggedInHeaderMenuIcon, ....  
}

getElementById(obj,ele,ByRef tracker){
      if obj.document.getElementById(ele){
            GuiControl,,tracker, OK
        }
        else
      {
        GuiControl,,tracker, FAIL
      }
}

loginForm(){
   
		WB.Document.getElementbyId("username").Click()       ;~NOT WORKING
				SendRaw, testuser                                                   ;~NOT WORKING
		WB.Document.getElementbyId("password").Click()      ;~NOT WORKING
				SendRaw, testpass                                                        ;~NOT WORKING
		WB.Document.getElementbyId("signIn").Click()            ;~NOT WORKING
}

FilePrepend(fileIN, string){
   IfNotExist, %fileIN%
      return false
   input := FileOpen(fileIN, 0)
   ,text := input.Read()
   ,input.Close()
   ,output := FileOpen(fileIN, 5)
   ,output.WriteLine(string)
   ,output.Write(text)
   ,output.Close()
   return true
}


; ****************************************************************************************
; *      PROG SETUP
; ****************************************************************************************
 
 main:
{
   Gosub,init
   url:="insertwebsitehere"
   WB.Navigate(url)
   loop
      If !WB.busy
         break
   return
}

init:
{
   OnExit,terminate
   Gui, +LastFound +OwnDialogs
   Gui, Add, ActiveX, w600 h500 x530 y10 vWB hwndATLWinHWND, Shell.Explorer
   WB.silent := true
   gui,show, w1140 h515 , SCMT v2
	return
}


runtests:
runit:
{

getElementById(WB,"header",HeaderStatus)
getElementById(WB,"content",ContentStatus)
getElementById(WB,"footer",FooterStatus)
getElementById(WB,"horizontalNavigation",MenuStatus)
   sleep 2000

getElementById(WB,"username",UsernameStatus)
getElementById(WB,"password",PasswordStatus)
getElementById(WB,"errorMessage",LoginValidator)
   sleep 2000

loginForm()
   sleep 8000

getElementById(WB,"searchHeader",FirstHeaderStatus)
getElementById(WB,"kadHeaing",SecondHeaderStatus)
getElementById(WB,"profileMenu",LoggedInProfileMenu)
getElementById(WB,"headerMenuIcon",LoggedInHeaderMenuIcon)
   Sleep 2000
   
return
}




GuiClose:
terminate:
{
   Gui, Destroy
   ExitApp
}

Restart:
reload
return
GTFO:
ViewLogs:
ClearLogs:
Paused:
RestartByUser:
return
Anyone knows how to send data do the GUI Control?
The function is not working, as the form does not receive data....
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Auto-login problem

02 Dec 2018, 20:51

Got it... It was a case of Speedy Gonzales.

Code: Select all

loginForm(){
		WB.Document.getElementbyId("username").Click()
         Sleep 1000
			SendRaw, testuser
         Sleep 1000
		WB.Document.getElementbyId("password").Click()
         Sleep 1000
			SendRaw, testuser
         Sleep 1000
		WB.Document.getElementbyId("signIn").Click()
}
Missing sleeps.... and im pretty sure that with a dumb mistake like this, im off to bed aswell....
:trollface:
Zubarm
Posts: 18
Joined: 11 May 2022, 01:05

Re: Auto-login problem

28 Jul 2022, 15:24

Hi all

I am struggling with the login also. It is when I put in the script into start up folder it wont start up automatically?

What can the issue be?

Code: Select all

AA=zzz ;-- Username
BB=zzz ;-- Password
cc:=" link “
dd=Authentication Server - Google Chrome ;-- wait for this in title
;--- end your variables ----------------
Settitlematchmode,2
;-- when not activated use default browser
;IXE=%A_programfiles%\Mozilla Firefox\firefox.exe
;IXE=%A_programfiles%\internet explorer\iexplore.exe
;IXE=%A_programfiles%\SeaMonkey\seamonkey.exe
;IXE=%A_programfiles%\Maxthon\Bin\Maxthon.exe
IXE=%A_programfiles%\Google\Chrome\Application\chrome.exe
Run,%IXE% %cc%,,max
send,{TAB 3}
send,%aa%
sleep,500
send,{TAB}
sendraw,%BB%
sleep,500
send,{TAB}
sleep,500
send,{ENTER}
sleep,1500
send,{TAB 5}
send,{ENTER}
;ExitApp
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], JoeWinograd, yabab33299 and 117 guests