That will automatically open and
Fill in your username and password
Then log you into any website fully automated?
Ever since I learned how to use a script to automate a browser
I have been using scripts to automate and log in to websites.
If you also see the benefit in that
Then in this tutorial:
I will show you step by step how you can easily make shortcuts that automatically login.
At the end of this post, you can get the script as a free download
Degree of difficulty:
In this tutorial we will make a script using the free scripting language AutoHotkey, it will open and log you in using the Internet Explorer browser.
Before we start, all you need are 2 things:
And 14 lines of plain text from this step by step tutorial.
Novices are recommended to have a look at this Tutorial
Example video: (0:21)
Now let’s get on with the step by step on how to make a script that will automate your login to any website using Internet Explorer.
Frist I’ll just pick a site that most of us know “Facebook” but remember that you can use this how-to for almost any website.
The File to shortcut:
We start by making a new script
Now if you have AutoHotkey installed you can skip step one in this list.
How to create a new script:
- Download and install AutoHotkey.
- Right-click an empty spot on your desktop or in a folder of your choice.
- In the menu that appears, select New -> AutoHotkey Script. (Alternatively, select New -> Text Document.)
- Type a name for the file, ensuring that it ends in .ahk. For example: Testing.ahk
- Right-click the file and choose Edit Script.
Each script is just a plain text file containing commands that will be executed by AutoHotkey.exe
The 14 lines of text:
On the two first lines you will store your login info in two variables. ( Remember that this is a plain text file so if anyone has access to this file your password will be readable )
My_User_Name := "jackiesztuk@Somemail.com" My_Pass_Word := "funny541"
Then we will make a webbrowser object
For this we will use the function ComObjCreate
And then we use the browser object returned from that function
This object is then stored in the variable “web_browser”
web_browser := ComObjCreate("InternetExplorer.Application")
A thing to note is that the web browser window starts out invisible by default
So we will set the browsers visible property to true
This way it will be visible so we can see it.
web_browser.Visible := true
Now we have a visible web browser object in a variable aka “web_browser”
Next we will use this object to navigate the IE web browser
For this we will use the browsers navigate method
Lets navigate to Facebook
Now the browser will navigate to the URL “www.facebook.com”
Waiting for a web page to load:
But for us to know how long this navigation will take
We will use another property of the browser object
The busy property, this property will be true as long as the browser is busy
So we will test for this with a while loop
while web_browser.busy ; a while loop is a way to keep the script testing an IF like expression sleep 100 ; IF web_browser.busy is true then sleep 100 milliseconds
This while loop will test the busy property every 100 milliseconds aka 10 times a seconds
So as soon as the web browser stops being busy the while loop will break
And the script will go onto the next lines
So now we or the browser is done navigating to “www.facebook.com”
Automatically interacting with a website:
Facebook is an html document that’s now loaded in the web browser object
So for us to automate this site we will need to go through the document object
Like this “web_browser.document”
Now it’s time to automatically input our username and password
For this we will need to know what input fields to use
This we can do with other script tools or the browser’s build in tools
This time we will use the IE browser’s “DOM Explorer” tool
You do this by manually opening an Internet Explorer browser and navigate to Facebook
Now press your right mouse button over the “Email or phone” field and pick
the “Inspect element” item from the drop down menu that appears
This will open Explores “DOM explorer” sub window
In this window you will see a line that is selected
looking something like this
<input name=”email” tabindex=”1″ id=”email” type=”text” value=””>
From this line we will need the value of the “id” Attribute
So looking at this line will tell us that here the “id” is “email” so let’s use that
Now to use this element we will store it in a variable let’s call it “username_input”
To do this we will use the document objects getElementById function
It looks like this
username_input := web_browser.document.getElementById("email")
That line gets the element with the id = “email” and puts it in our variable “username_input”
Now we can use this webpage element via our variable “username_input”
Automated filling of web fields:
So to automatically fill in the value of the input field with our username
We will set the “value” property of the element to the data in our “My_User_Name” variable
username_input.value := My_User_Name
So now the “email or phone” input field will hold our username
Next we will do the same thing for the password.
Go to www.facebook.com and move your mouse over the password input field
Now right-click it then select the “Inspect element” item from the drop down menu
This will open the DOM tool with a selected line looking something like this:
<input name=”pass” tabindex=”2″ id=”pass” type=”password”>
From this line we will again need the value of the “id” Attribute
so looking at this line we can tell that here the “id” is “pass” so we will use that
Again we take the element and store it in a variable we call “password_input”
To do this we will again use the document objects getElementById function
So it looks like this for the password
password_input := web_browser.document.getElementById("pass")
That line gets the element with the id = “pass” and puts it in our variable “password_input”
Ones again we can use this webpage element via our variable “password_input”
Okay to automate the filling in of the value of the password input field with our password
Set the “value” property of the webpage element to the data in your “My_Pass_Word” variable
password_input.value := My_Pass_Word
So now the “password” input field will hold our password
Clicking an html Element:
The last thing we need to do is click the Login Button
How to do that? You say!
Frist we go to www.facebook.com and move our mouse over the login button
When over the login button you press the right mouse button and
select the “Inspect element” item from the drop down menu
This will show the login button element selected in the DOM tool
The line will look something like this:
<input tabindex=”4″ id=”u_0_n” type=”submit” value=”Log In”>
This time we just need to click the button element
So we will only use the element by its “id”, but not store it in a variable
For this we will use almost the same method as with the other elements
So we will use the document objects getElementById function again
And also the elements “click” method
It will look something like this for the login button.
That line gets the element with the id = “u_0_n” and clicks it with the “click()” method
Ending a script:
Now saving and running this script will open an IE browser
And navigate to www.facebook.com and then automatically login
That is one way to do an automated login to a website like Facebook, now you can use this method to do the same for almost any website you need, this can also be made to open by hotkey and also to automatically login to open websites and more.
Keep telling me if you need more guides to make things like this or anything I missed or does this kind of post even help you out?
If you have any Questions you can always use the comments or contact page
To use your new script, continue as follows:
- Save and close the file.
- Double-click the file to launch it.
To find, exit or edit the script, right-click the green “H” icon in the taskbar notification area.
- Scripts like this can also use exitapp as the ending line to not have to many scripts running simultaneously, as each will have its own icon in the taskbar notification area.
- Username and password can also be input by the user at startup as seen in the compiled exe below.
- To have a website launch and login automatically when you start your computer, create a shortcut to the script file in the Start Menu’s Startup folder.