WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Gmail Login

 Keywords: Gmail Account Login Auto-Login

Sample 1:

;***************************************************************************
;**                  Gmail Auto-Login
;**             Logs into your Gmail account online.
;**
;** Developer: Deana Falk 2014.04.02                 
;***************************************************************************

gmailacct = 'soandso@gmail.com' 
gmailpswd = '****'


#DefineFunction udfIEPageLoadWait( objIE )
    ; Wait for webpage to load
    While !(objIE.readyState == 'complete' || objIE.readyState == 4 )
       Timedelay(0.1)            
    EndWhile
    While !(objIE.document.readyState == 'complete' || objIE.document.readyState == 4 )
       Timedelay(0.1)
    EndWhile
    Return 1 
#EndFunction

url = "http://www.gmail.com"

; Initialize MSIE object
oIE   = ObjectCreate("InternetExplorer.Application")
oIE.Visible = @TRUE ; Change to @FALSE to hide the process from the user
oIE.Navigate(url)

; Wait for webpage to load
udfIEPageLoadWait( oIE )

;***************************************************************************
; Get forms collection 
;***************************************************************************
; Get document object
oDoc = oIE.Document

; Forms Collection  
oForms = oDoc.Forms
oForm = 0
if oDoc != 0 ; Check if you have a valid document handle
   ; Loop through the collection of forms using index
   count = oForms.Length
   For index = 0 to count-1 
         oForm = oForms.Item(index)
         If ObjectTypeGet(oForm)=="EMPTY" then continue
           formname = oForm.name
           if formname == 'gaia_loginform' then break
   Next   
Else
   Pause('Notice','Unable to obtain a handle to the document object on this webpage. Check URL.')
Endif
If oForm == 0
   Pause('Notice','Uable to locate the form on this page!')
   ; Quit
   oIE.Quit
   
   ; Close open COM/OLE handles
   oDoc = 0
   oIE = 0
EndIf

ignorehidden = 1
inputonly = 1
elementindex = 0
cElements = oForm.Elements
count = cElements.Length
ForEach oElement in cElements
      ; Get element attributes
      ; Alternatice option: oElement.getAttribute("attributename")
      tag = oElement.nodeName ;The value of tagName is the same as that of nodeName.
      type = StrUpper(oElement.Type) 
      id = oElement.Id
      name = oElement.Name
      value = oElement.Value   

      ; Check if user wants to ignore HIDDEN form elements
      If ignorehidden
          If StrUpper(type) == 'HIDDEN' then continue
      EndIf

      ; Check if user wants to see non INPUT form elements
      If inputonly
         If StrUpper(tag) != 'INPUT' then continue
      EndIf

      ; Highlight each element on the form
      oElement.style.border = "1mm solid red"
      
      ; Set focus on element
      If !oElement.disabled
         ErrorMode(@off)
         oElement.Focus()
         ErrorMode(@cancel)
      EndIf
      
      ; Display results
      ;Pause('','Element Index: ' : elementindex : @lf :'Tag: ' : tag : @lf : 'Type: ' : type : @lf :'Id: ' : id : @lf :'Name: ' : name : @lf :'Value: ': value )

      Switch @True
         case name == 'Email'
            if value == '' then oElement.Value = gmailacct
            ;Message( name, oElement.Value )
         break

         case name == 'Passwd'
            if value == '' then oElement.Value = gmailpswd 
            ;Message( name, oElement.Value )
         break

         case name == 'signIn'
            ; Click button 
            ;oElement.Click  
            
            ;or

            ; Click button on IE 9 and newer
            ; createEvent initEvent DispatchEvent
            oEvent = oIE.document.createEvent("HTMLEvents")
            oEvent.initEvent("click", @TRUE, @TRUE)
            oElement.dispatchEvent(oEvent)
            oEvent = 0
         break

      EndSwitch
     

      ; Remove element highlight
      oElement.style.border = ""

      ; Increment element counter
      elementindex = elementindex+1 
Next

Pause('Gmail Auto-Login','You should now be logged in')

; Quit
;oIE.Quit

; Close open COM/OLE handles
oDoc = 0
oIE = 0
Exit

Sample 2 (simplified code sample):

;***************************************************************************
;**                  Gmail Auto-Login Simple
;**             Logs into your Gmail account online.
;**
;** Developer: Deana Falk 2014.04.02                 
;***************************************************************************

gmailacct = 'soandso@gmail.com' 
gmailpswd = '****'

; Ensure that you are signed-out of Gmail
  
url = "http://gmail.com" 
oIE = ObjectCreate('internetexplorer.application') 
oIE.visible = @true; 
oIE.navigate(url); 
while oIE.Busy  
    TimeDelay(1)
endwhile

; Wait for element
;While @true 
   oElement = oIE.Document.getElementById("Email")
;   type = ObjectTypeGet(obj)
;   if type != 'NULL' then break
;EndWhile
oElement.value = gmailacct


; Wait for element
;While @true 
   oElement = oIE.Document.getElementById("Passwd")
;   type = ObjectTypeGet(obj)
;   if type != 'NULL' then break
;EndWhile
oElement.value = gmailpswd 

; Wait for element
;While @true 
   oElement = oIE.Document.getElementById("signIn")
;   type = ObjectTypeGet(obj)
;   if type != 'NULL' then break
;EndWhile

; Click button 
;oElement.Click              
;or
; Click button on IE 9 and newer
; createEvent initEvent DispatchEvent
oEvent = oIE.Document.createEvent("HTMLEvents")
oEvent.initEvent("click", @TRUE, @TRUE)
oElement.dispatchEvent(oEvent)

oEvent = 0
oElement = 0 
oIE = 0
Exit


Article ID:   W18128
Filename:   Gmail Login.txt
File Created: 2014:04:02:10:47:20
Last Updated: 2014:04:02:10:47:20