Requirement:
You want to have a web page pre-launched with automatic username and password login to the web page.
Using VBScript:
Using VBScript you can achieve this requirement where you create an Internet Explorer Application object and have complete access/control to it’s elements/content and their properties.
- Create IE Object: Set ObjIE = CreateObject(“internetexplorer.application”)
- Launch web page: ObjIE.Navigate “http://localhost/TestApp/User001/Login”
- Wait for page to load: WScript.Sleep 500 in Do Loop While ObjIE.ReadyState < 4 And ObjIE.Busy
- Input username: .getElementByID(“userId”).value = “Visitor”
- Input password: .getElementByID(“password”).value = “password”
- Click Sign-in Button: .getElementByID(“signIn_OK”).Click
Sample Script:
'===============================================================================
' Script name : Auto-Launch-Login-TestApp-IEBrowser.vbs
' Author : Govardhan Gunnala
' Objective : Script to Automatically Launch and Login to the TestApp in IE Browser.
'
' $Header: $
'===============================================================================
' Global Statements
'===============================================================================
On Error Resume Next
'===============================================================================
' Global Constants and Variables
'===============================================================================
Dim ObjIE
Dim strUserName
Dim strUserNumber
'===============================================================================
' Initialize Globals
'===============================================================================
'===============================================================================
' main()
'===============================================================================
Set WshShell = CreateObject("WScript.Shell")
Set ObjIE = CreateObject("internetexplorer.application")
strUserName = wshShell.ExpandEnvironmentStrings("%USERNAME%")
strUserNumber = Mid(strUserName, 5, 8)
ObjIE.Navigate "http://localhost/TestApp/User" & strUserNumber & "/Login"
ObjIE.Visible = TRUE
Wait ObjIE
With ObjIE.Document
.getElementByID("userId").value = "Visitor"
Wait ObjIE
.getElementByID("password").value = "password"
Wait ObjIE
.getElementByID("signIn_OK").Click
End With
'===============================================================================
' Functions
'===============================================================================
Function Wait(ObjIE)
Do
WScript.Sleep 500
Loop While ObjIE.ReadyState < 4 And ObjIE.Busy
End Function
'===============================================================================
' End
'===============================================================================