Question

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?

Was it helpful?

Solution

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

OTHER TIPS

Salvete! I just answered a similar post here, to perform this exact procedure, please take a look: How to wait until WebBrowser is completely loaded in VB.NET?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top