Skip to main content

How to automate login to a web site.

evel: Intermediate
How to automate login to a web site.
Login automation - Internet Explorer & Web Browser Control
Sometimes, we need to login to gain access to complete site. I will show you a way to log to, which requires user id, password and to push a button.
Before go further showing code, we need to know how login process takes place.
Sites needs to know where you enter things and we need too. Generally, textboxes used to enter id and password have names to diferentiate among others textboxes and it is marvelous. We need those names too.

Those names are located inside HTML code. We have to "read" HTML code the first time we access login page.

To this time, i already did that. The textbox name for user id is: login and textbox name for password is: passwd. The name of the button we need to press is: enter.

By now, you already know how to set object variables for InternetExplorer and you have been using WebBrowser control, so, i will not explain here again.

Private Sub Form_Load()
set IE = New InternetExplorer
With IE
.navigate ""
.visible = True
End With
End Sub

Let's go to DocumentComplete event:

Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
'Url could change so take care of it ;)
If InStr(1, URL, "", vbTextCompare) Then
Dim inp As Object
Set inp = IE.document.all.Item("login")
inp.Value = "myname" 'replace with your id

Set inp = IE.document.all.Item("passwd")
inp.Value = "passwrd" 'replace with your password

Set inp = IE.document.all.Item("enter")
End if
End If
End Sub

A variation:

Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
'Url could change so take care of it ;)
If InStr(1, URL, "", vbTextCompare) Then
IE.document.all.Item("login").value = "myname" 'replace with your id

IE.document.all.Item("passwd").Value = "passwrd" 'replace with your password

End if
End If
End Sub
Post a Comment

Popular posts from this blog

Compact and Repair an Access Database. Add Ref. to : AdoDb, Jro

< ?xml version="1.0" encoding="utf-8" ?>

using ADODB;
using JRO;
using System.Configuration;
using System.Data.OleDb;
using System.IO;

public class CompactAndRepairAccessDb : System.Windows.Forms.Form
private System.ComponentModel.Container components = null;
private JRO.JetEngine jro;
private System.Windows.Forms.Button btnConfirm;
private System.Windows.Forms.TextBox tbxOriginalDbSize;
private System.Windows.Forms.TextBox tbxCompactedDbSize;
private OleDbConnection cnn;

public CompactAndRepairAccessDb() {

FileInfo fi = new FileInfo( ConfigurationSettings.AppSettings["PathOriginal"] );
int s = Convert.ToInt32( fi.Length/1000 );
this.tbxOriginalDbSize.Text = s.ToString() + " kb";

private void btnConfirm_Click(object sender, System.EventArgs e) {
// First close all instances of the database

VBScript to Automate login into gmail

Dim IE
Dim crtScreen
Set IE = CreateObject("InternetExplorer.Application")
USERNAME = "saudaziz"

With IE
.navigate ""
End With

'wait a while until IE as finished to load
Do while IE.busy
set WshShell = WScript.CreateObject("WScript.Shell")
Do While UCase(IE.Document.readyState) <> "COMPLETE"
WScript.Sleep 100
set WshShell=nothing
IE.document.all.Item("Email").value = USERNAME
IE.document.all.Item("pASSWD").value =pASSWORD
Set IE = Nothing