PDA

View Full Version : Solved: Web browser control



Croeg
05-10-2007, 10:18 AM
Hello

I've created a form and added the web browser control to it along with a command button. When the button is pressed, the browser is directed to a website. The website is then redirected (not every time) to a login page where the user must enter user name and password.

It's very inconsistent. Usually once the user name and password are entered, I'm not redirected to login page.

:think: Is there a way to detect when the webpage is redirected so that I might be able to enter sendkeys function to automatically enter user name and password?

Thanks.

Croeg

tstom
05-10-2007, 02:36 PM
Yes. What is the url? Every webpage is unique and you will need to test for a url or some other document property to determine where you are at. I can help you if you can provide the URL. You might also consider checking for the associated cookie and know beforehand. This can be done by way of code without using sendkeys. Also the login can be done without sendkeys...

Croeg
05-10-2007, 04:16 PM
Hi tstom,

Thanks for responding.

I sent you a private message with the URL address.

Thanks

Croeg

Croeg
05-11-2007, 05:36 AM
tstom,

Thanks so much for your help....this worked perfectly !!!! :thumb



Option Explicit
Private Const UserName As String = "Some Username"
Private Const PassWord As String = "Some Password"
Private Attempts As Integer
Private Sub CommandButton1_Click()
WebBrowser1.Navigate "https://www.xxx.com"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If TypeOf pDisp Is WebBrowser Then
If InStr(pDisp.Document.Title, "Global Logon") <> 0 Then
If Attempts < 3 Then
pDisp.Document.all("userid").Value = UserName
pDisp.Document.all("password").Value = PassWord
pDisp.Document.all("btnSubmit").Click
Attempts = Attempts + 1
End If
End If
End If
End Sub


Croeg