Skip to content Skip to sidebar Skip to footer

Automatically Logging In Website Using VB Script

I am trying to automate login process for a website. I used below code Dim objIE Dim htmld Set objIE = CreateObject('InternetExplorer.Application') objIE.Visible = False objIE.Navi

Solution 1:

Try these additional checks:

Dim IE
Set IE = CreateObject("InternetExplorer.Application")
With IE
    .Visible = False
    .Navigate "website.com" ' website.com is example not the original
    Do While .Busy Or Not .readyState = 4: WScript.Sleep 100: Loop
    Do Until .document.readyState = "complete": WScript.Sleep 100: Loop
    Do While TypeName(.document.getElementById("login_id")) = "Null": WScript.Sleep 100: Loop
    .document.getElementById("login_id").Value = "ss"
End With

Solution 2:

I wrote a vbscript to do just what you asked, and I use it all the time. It opens up one tab in IE, and logs in, then it opens two more tabs to different pages in our application.

On Error Resume Next

ECRecord = "http://vm195/views/welcome.action"
ECJobs = "http://vm195/views/job/jobList.action?query.MaxResults=500&allStates=false%2F&query.ActiveState=true&query.ActiveState=false%2F&query.PendingState=true&query.PendingState=false%2F&query.CompletedState=false%2F&query.FailedState=true&query.FailedState=false%2F&query.CancelledState=true&query.CancelledState=false%2F&query.HoldState=true&query.HoldState=false%2F&query.jobTypes=-1&allFreqs=true&allFreqs=false%2F&query.DailyFrequency=true&query.DailyFrequency=false%2F&query.IntervalFrequency=true&query.IntervalFrequency=false%2F&query.SetDateFrequency=true&query.SetDateFrequency=false%2F&query.SingleFrequency=true&query.SingleFrequency=false%2F&query.patientId=&query.accessionNumber=&query.studyPk=&query.dateRange=-3&query.beginDate=&query.endDate=&Submit=Search&refreshRate=120"
ECConfig = "http://vm195/views/org/organizationTree.action"

Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
'open a new window
oIE.Navigate2 ECRecord

Do While (oIE.Busy)
   WScript.Sleep 10
 Loop                    


 Set Helem = oIE.document.getElementByID("username")
 Helem.Value = "tsu500" ' change this to yours
 Set Helem = oIE.document.getElementByID("password")
 Helem.Value = "production" ' change this to yours

 oIE.Document.getElementsByName("submit_button").Item(0).Click

 'Set Helem = oIE.document.Forms(1)
 'Helem.Submit


WScript.Sleep 500


Do While (oIE.Busy)
   WScript.Sleep 10
 Loop  


'open url In new tab
oIE.Navigate2 ECJobs, 2048
WScript.Sleep 100
oIE.Navigate2 ECConfig, 2048

Set oIE = Nothing 

Post a Comment for "Automatically Logging In Website Using VB Script"