views:

453

answers:

1

I am using a webbrowser control to login to a website.

WbBrowser.Navigate("http://www.foo.com/login.php")

Once the page is loaded I login using the following code

While WbBrowser.ReadyState <> WebBrowserReadyState.Complete
            Application.DoEvents()
        End While

WbBrowser.Document.GetElementById("user_login").SetAttribute("Value", "username")
WbBrowser.Document.GetElementById("user_pass").SetAttribute("Value", "password")
WbBrowser.Document.Forms("loginform").InvokeMember("submit")

This works fine. On successful login I have to navigate to another page. This will happen only if the login is correct. The issue here is as son as the login page is loaded the readystate of webbrowser control becomes complete and even before the I login to website the next line of code gets executed and results in an error as I am not logged in.

WbBrowser.Navigate("http://www.foo.com/page2.php")

How can I make my application wait for the login to be complete and then execute the above line of code. Any ideas?

A: 

Try keep track of your application state in a variable, and use the webbrowser.DocumentCompleted event to test if the login passed.

Wez