I recently started learning javascript, and I'm currently trying to make a small script to automate a login procedure by filling the user name/password fields, and then clicking the 'Submit'-button.
My code is as follows:
window.open("");
document.getElementById('ctl00_Username').value = "XXXX";
document.getElementById('ctl00_Password').value="XXXX";
document.getElementById('ctl00_ButtonLogin').click();
If I run it once, the site is opened but no text fields are filled.
If I run the code twice (when the site is already opened) the login is successful.
I tried putting "console.log" after "window.open", but for some reason that never seems to get called.
What might I be doing wrong?
Edit: Removed unnecessary code. I am also no longer sure that the document-object actually points to the newly opened window. Calls to "console.log" and "alert" don't seem to do anything, either.
Is it possible to get the correct document-object from the window? Is it even possible to use "window.open" and then access the new document-object? Help would be greatly appreciated!
1.Pass your values as query string. Example: www.test.com?username=bro&password=bro. 2.On the other page paste the below code.
3.Now paste this code too.
4.You will be having values in the above variables.Enjoy doing whatever you want.
A reference to the window is returned from the window.open call, you can use it to modify the window.
You also probably need to wait until the document is ready (aka loaded). Using jquery below