Page 1 of 1

Auto-login problem

Posted: 06 Nov 2018, 13:25
by Portwolf
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

Re: Auto-login problem

Posted: 06 Nov 2018, 13:29
by Portwolf
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>

Re: Auto-login problem

Posted: 07 Nov 2018, 06:36
by Portwolf
up :)

Re: Auto-login problem

Posted: 07 Nov 2018, 07:44
by Drugwash
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).

Re: Auto-login problem

Posted: 07 Nov 2018, 11:31
by swagfag
why is the data disappearing an issue? as long as its correct, it should log u right in.

Re: Auto-login problem

Posted: 07 Nov 2018, 11:50
by Drugwash
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". :(

Re: Auto-login problem

Posted: 08 Nov 2018, 03:33
by Portwolf
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.

Re: Auto-login problem

Posted: 08 Nov 2018, 07:05
by Portwolf
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)

Re: Auto-login problem

Posted: 08 Nov 2018, 08:40
by Drugwash
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.

Re: Auto-login problem

Posted: 10 Nov 2018, 12:21
by shipaddicted
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 

Re: Auto-login problem

Posted: 10 Nov 2018, 16:03
by Portwolf
@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

Re: Auto-login problem

Posted: 12 Nov 2018, 10:58
by Drugwash
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. :?

Re: Auto-login problem

Posted: 13 Nov 2018, 19:41
by Portwolf
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.

Re: Auto-login problem

Posted: 14 Nov 2018, 12:22
by Drugwash
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.

Re: Auto-login problem

Posted: 14 Nov 2018, 18:44
by Portwolf
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..

Re: Auto-login problem

Posted: 14 Nov 2018, 23:54
by Drugwash
Image

Re: Auto-login problem

Posted: 20 Nov 2018, 07:47
by Portwolf
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...

Re: Auto-login problem

Posted: 02 Dec 2018, 20:42
by Portwolf
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....

Re: Auto-login problem

Posted: 02 Dec 2018, 20:51
by Portwolf
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: