Vb.net – handle security popup using vbscript (without QTP/Selenium)

vb.netvbscriptwsh

I am automating an application login using vbscript.

I am using the code –

Dim objIE
Set objIE = Wscript.CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "https://portal url"

after this, there is a security pop up which asks for user name and password.

I dont want to disable the pop-up. Rather i want to be able to put user id and password in to it.

I tried handling it through

NewWindow3 method and
NewWindow2 method

which MSDN has provided for handling extra windows(This for development rather than for automation I guess) but does not work out.

`objIE.Document.GetElementByID

also does not work out becuse the pop-up does not come under 'Document' object. it comes directly under objIE, but could not find anything to handle it.

Best Answer

I use following code for pass credentials to the Windows Authentication dialog. I hope it helps.

Dim objIE, objWshShell
Set objIE = WScript.CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "http://url"
Set objWshShell = WScript.CreateObject("WScript.Shell")
With objWshShell
    WScript.Sleep 100
    .SendKeys "myusername" 'Focused by Default - Username
    WScript.Sleep 100
    .SendKeys "{TAB}" 'Skip To Password Field
    WScript.Sleep(100)
    .SendKeys "mypassword" 'Password     
    WScript.Sleep 100
    .SendKeys "{TAB}" 'Skip To "Remember Me" Checkbox
    WScript.Sleep 100
    .SendKeys "{TAB}" 'Skip To Submit Button
    WScript.Sleep 100
    .SendKeys "{ENTER}" 'GO
End With
Set objWshShell = Nothing
Set objIE = Nothing
Related Topic