Question

After some research on the WebBrowser DocumentCompleted issue, I've inserted my login attempt into the DocumentCompleted Event Handler.

Here's my code:

public void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        wb.Navigate("fooPage");
        var browser = (WebBrowser)sender;

        HtmlElement email = CookieReader.GetElement("email", browser);
        HtmlElement password = CookieReader.GetElement("pass", browser);
        email.SetAttribute("email", "foo@something.com");
        password.SetAttribute("pass", "foo");
        HtmlElement loginElement = CookieReader.GetElement("fooLog", browser);
        loginElement.InvokeMember("click"); //wb_DocumentCompleted Method Continues...

I didn't manage to login (double checked that I got the login button right). It seems that the problem is with the ReadyState property of the browser object. It's always loading, while the IsBusy property is always False. Also, the page was supposed to finish loading because the DocumentCompleted event fired. Any ideas how this even possible?

Moreover, when debugging, the InvokeMember method changes the html INPUT element and a disabled tag appears (disabled=\"\" - which is HTML5 disabled="disabled" if I'm not mistaken). I don't know why this tag is added (wasn't there before), and if it's related in any way to the permanent Loading ReadyState of the page... insights and/or advises will be much appreciated!

Was it helpful?

Solution

I had the same problem. The DocumentCompleted event fires more that once in a single load. I think the first is not the real one. I think you should create a BackgroundWorker and start it when the DocumentCompleted event fires. It should wait a few seconds before do the job. That will definitely work.

You should start the BackgroundWorker only once.

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