WebBrowser ActiveX Question

B

BenWeber

I use the function below to open a new webbrowser and login to the page.

I'm trying to see if the login is successful and if so i go to the next
page, navigate from there somewhere else (only available if successful) and
process the text on that page.

2 questions:

1) The function below works if the password and user are correct. However
the check for invalid login does not. This is because, at that point, the
focus is in the blank Username control, so select all doesn't select anything
and the clipboard remains what it was (as opposed to getting the contents of
the page). Is there a way to access the contents of the page? I can't
select another object on the screen i don't think, because i don't think you
can set the focus to something that isn't an editable control (ie i'd like
have a method call that does the same thing as clicking on a blank part of
the window so selectall will work).

2) Obviously, select all and copy aren't the most elegant solutions. I have
been unable to use anything like IE.DocumentText for some reason. Any
suggestions on how i can access the page without using selectall?

The URL i'm doing this with is: http://online.sokker.org/logon.php

-Begin function-

Public Function LoginToIE(ByRef IE As Object, URL As String, UserName As
String, Password As String, Pause As Long) As Boolean
On Error GoTo Err_Handler
Dim ClipboardStr As String

LoginToIE = False

Set IE = CreateObject("InternetExplorer.Application")
Call WaitForIE(IE, Pause)

IE.Navigate URL
IE.Visible = True
Call WaitForIE(IE, Pause)

IE.Document.all("ilogin").select
IE.Document.all("ilogin").Value = UserName
IE.Document.all("ipassword").select
IE.Document.all("ipassword").Value = Password

SendKeys "{ENTER}"

Call WaitForIE(IE, Pause)

IE.Document.ExecCommand ("SelectAll")
IE.Document.ExecCommand ("Copy")

ClipboardStr = ClipBoard_GetData()

If InStr(ClipboardStr, "Invalid Login") > 0 Then
IE.Quit
Set IE = Nothing
MsgBox ("The User ID and Password supplied do not seem to be
correct.")
Exit Function
End If

LoginToIE = True

Exit Function

Err_Handler:
MsgBox err.Description
Set IE = Nothing

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top