How to assign value to GetElementById("user-email").value Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
thomastthai
Posts: 18
Joined: 12 Mar 2020, 01:51

How to assign value to GetElementById("user-email").value

10 May 2020, 04:00

I would appreciate help to find out why the values assigned to these input elements aren't getting updated?

Code: Select all

ieVisible := True

ie := ComObjCreate("InternetExplorer.Application")
ie.visible := ieVisible ; Show Internet Explorer window?
ie.ToolBar := false
ie.Navigate("https://cgcookie.com/login") 

; wait for the browser to load
while (ie.ReadyState != 4 or ie.Document.ReadyState != "complete" or ie.busy)
{
	sleep 100
}

ie.document.GetElementById("user-email").value := "me@myselfandi.com"
ie.document.GetElementById("user-password").value := "ABCDEF"
ie.document.GetElementsByClassName("btn btn-primary btn btn-primary btn-lg btn-block")[0].click()
I can't tell if Javascript is controlling these elements that's preventing the injection of values.

Additionally, the .focus, .onchange(), and .fireEvent() don't seem to have an effect.

Code: Select all

ie.document.GetElementById("user-email").focus
ie.document.GetElementById("user-email").onchange()
;ie.document.GetElementById("user-email").fireEvent("onchange")
I get that I could use:

Code: Select all

sleep 1000
send me@myselfandi.com{Enter}
sleep 1000
send ABCDEF{Enter}
But that requires the browser to be visible and active. I would like to run this in the background.

Update 1:

I believe these input fields could be connected to some event handlers.

Update 2:
CGCookie Login Event Listeners.png
CGCookie Login Event Listeners.png (31.06 KiB) Viewed 1014 times


It looks like there are JQuery event listeners.

I also watched @Joe Glines video ( https://www.youtube.com/watch?v=v6vD_Pzy7AM ). I got a better understanding but not enough to solve this challenge.
gregster
Posts: 9114
Joined: 30 Sep 2013, 06:48

Re: How to assign value to GetElementById("user-email").value  Topic is solved

10 May 2020, 22:08

No triggering of eventlisteners needed.
The problem is simply that you have typos in your IDs - like this, they can't be found.
That happens ;) .

It should be user_email and user_password instead of user-email and user-password:

Code: Select all

ieVisible := True

ie := ComObjCreate("InternetExplorer.Application")
ie.visible := ieVisible ; Show Internet Explorer window?
ie.ToolBar := false
ie.Navigate("https://cgcookie.com/login") 

; wait for the browser to load
while (ie.ReadyState != 4 or ie.Document.ReadyState != "complete" or ie.busy)
{
	sleep 100
}

ie.document.GetElementById("user_email").value := "me@myselfandi.com"
ie.document.GetElementById("user_password").value := "ABCDEF"
ie.document.GetElementsByClassName("btn btn-primary btn btn-primary btn-lg btn-block")[0].click()
thomastthai
Posts: 18
Joined: 12 Mar 2020, 01:51

Re: How to assign value to GetElementById("user-email").value

11 May 2020, 00:00

Thank you @gregster! :bravo: It helps to have a fresh pair of eyes. I spent many hours double-checking typos and researching different options with event listeners. I can see how easy it was for me to overlook that typo though. Copying and pasting the id over from the web page would have been a way to avoid this type of mistake.

On the positive side, I now know more about event listeners!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Marium0505, mcl and 355 guests