VBScript to login into Gmail account

WScript.Quit Main

Function Main
  Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
  IE.Visible = True
  Resolution = Screen_Resolution()
  Width =  Resolution(0)
  Hight=  Resolution(1)
  IE.Top = 0
  IE.Left = 0
  IE.Width = Width
  IE.Height = Hight
  IE.Navigate "http://www.google.com/mail"
  Wait IE
  With IE.Document
    .getElementByID("Email").value = "<Username>"
    .getElementByID("Passwd").value = "<Password>"
    .getElementByID("gaia_loginform").submit
  End With
End Function

Sub Wait(IE)
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy
End Sub

Sub IE_OnQuit
  On Error Resume Next
  WScript.StdErr.WriteLine "IE closed before script finished."
  WScript.Quit
End Sub

Function Screen_Resolution()
Dim MyArray(1)
    Set objWMIService = GetObject("Winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0)
    For Each objItem in colItems
        intHorizontal = objItem.ScreenWidth
        intVertical = objItem.ScreenHeight
    Next
MyArray(0) = intHorizontal
MyArray(1) = intVertical
Screen_Resolution = MyArray

End Function

Comments

Unknown said…
Can any one help me in the following .......

How find the value like(Email, passwd, gaia_loginform") in the above script.
and

How to write a script a to click on login button, which should work in all in login forms..?
Amol Kanthe said…
You will get these values from source code of the webpage.
Unknown said…
Hi Amol
To get the source code to a notepad, is there any HTML code
Amol Kanthe said…
You can directly copy it to the Notepad.
Anonymous said…
Old script not working with new gmail account

Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://accounts.google.com/signin/v2/identifier?flowName=GlifWebSignIn&flowEntry=ServiceLogin#"
IE.Visible = True
While IE.Busy
WScript.Sleep 50
Wend
Set ipf = IE.document.all.identifier
ipf.Value = "username"
WScript.Sleep 5000
Set ipf = IE.document.all.password
ipf.Value = "password"
end if
Amol Kanthe said…
Yes. The script needs to be updated. Earlier the username and password textboxes were on the same page, now we need to enter username and password on different pages. The basic script will be the same just need to update this change.
Rahul dewan said…
how to open gmail in google chrome instead of internet explorer

Popular Posts

Vibium: The AI-Native Revolution in Test Automation is Here

AI in QA: Mastering the Future of Testing with Essential Tools

Mastering Selenium Exceptions for Robust Test Automation

Mastering Selenium Methods: A Technical Deep Dive

File System Object (FSO) - Working with Folders