0

Yes, this does seem like a very common question and trust me, I looked for a solution to this for quite a while now. It's about a WinForms-WebBrowser.

This right below doesn't seem to work because the page I'm loading seems to keep executing javascript, so it never completes (don't know if my assumption is right, but it definitely is never set to complete).

browser.DocumentCompleted += (sender, e) =>
        {
            if (browser.ReadyState != WebBrowserReadyState.Complete)
                return;
            //browser is done loading
        };
        elementToClick.InvokeMember("click");

This approach doesn't work either for whatever reason, literally no idea why.

browser.DocumentCompleted += (sender, e) =>
        {
            if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath)
                return;
            //browser is done loading
        };
        elementToClick.InvokeMember("click");

This should end up as a function such as PageLoad(), which I call after navigating to different browserdocuments. So Application.Doevents() is not an option as I need to wait until the new document is loaded before continuing. And neither is Thread.Sleep(x), because it needs to resume the code right when it's finished (speed matters here). Thread.Sleep(x) in a while-loop will completely stop my browser from loading.

Are there any different approaches? If there's information missing, please let me know.

Lesic
  • 136
  • 12
  • http://stackoverflow.com/a/20934538/1768303 – noseratio Jan 27 '16 at 22:07
  • @Noseratio I haven't tried your approach yet, but as there are a few timers running and ticking down on the document I navigated to I think the html will never be the same. Actually I think for me it doesn't matter if there's still script executing in the background, as the next link I want to click on will be there even when the JavaScript still is doing something. – Lesic Jan 28 '16 at 08:40

0 Answers0