DocumentCompleted multiple times - accepted StackOverflow answer not working

I am testing if my WebBrowser is complete:

webBrowser2.DocumentCompleted += (s, e) => { // Do stuff } 

The webpage I am accessing is like a lot of JS and iframes files, etc., so I use the following function to make sure it really loads.

 webBrowser2.DocumentCompleted += (s, e) => { if (e.Url.AbsolutePath != (s as WebBrowser).Url.AbsolutePath) { return; } // Do stuff } 

However, it still does not work. Am I doing something wrong or is it syntactically correct and is there some other error in my code?

+4
source share
3 answers

DocumentComplete can be launched several times for many reasons (frames, ajax, etc.). At the same time, for a specific document, the window.onload event will be fired only once. So, perhaps you can do your processing on window.onload . I simply answered the question of how this can be done.

+2
source

I use this (from an answer to SO to a similar question):

 void BrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url.AbsolutePath != (sender as WebBrowser).Url.AbsolutePath) return; //The page has finished loading. } 
+6
source

Just make sure that e.Url.AbsolutePath is a valid URL to which you went.

if (e.Url.AbsolutePath == TheActualURLString) {// This actual page load is complete}

+1
source

Source: https://habr.com/ru/post/1497871/


All Articles