axWebBrowser DocumentComplete
-
Hi ppl! In my program I need to catch the axWebBrowser1 'DocumentComplete' event. But I find out that this event happens more than 1 times !!!?? At some pages it even happens 7 or 8 times !! Why is this ??? And how I can tell if this is very last chance when it happens (document completly loaded) or there's will be more 'DocumentComplete' events ??? Please help - this is extremly important to me "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
-
Hi ppl! In my program I need to catch the axWebBrowser1 'DocumentComplete' event. But I find out that this event happens more than 1 times !!!?? At some pages it even happens 7 or 8 times !! Why is this ??? And how I can tell if this is very last chance when it happens (document completly loaded) or there's will be more 'DocumentComplete' events ??? Please help - this is extremly important to me "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
-
Hi man !! Thanks for the answer - very helpfull. But you see - I'm still having problems with determinate when exactly web page is loaded :( I'm trying to receive IHTMLCollection from axWebBrowser.Document from some news web site (the url is http://www.lenta.ru) For the very bad luck I choosed this site to test my collection with and I still receive a weird result :(( Sometimes the size of collection is 2069 elements and sometimes (I just hit refresh button I receive collection of 2065 (!) elements and so on... I don't know what to do :( Seems to me I can't really lock on the page and some elements are missing (?) sometimes ??? Any sugestions ??? "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
-
Hi man !! Thanks for the answer - very helpfull. But you see - I'm still having problems with determinate when exactly web page is loaded :( I'm trying to receive IHTMLCollection from axWebBrowser.Document from some news web site (the url is http://www.lenta.ru) For the very bad luck I choosed this site to test my collection with and I still receive a weird result :(( Sometimes the size of collection is 2069 elements and sometimes (I just hit refresh button I receive collection of 2065 (!) elements and so on... I don't know what to do :( Seems to me I can't really lock on the page and some elements are missing (?) sometimes ??? Any sugestions ??? "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
I'm having trouble understanding what your code is really doing. Where did this collection with 2056 elements come from? The axWebBrowser.Document itself shouldn't be changing, but its content will be. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek. -
I'm having trouble understanding what your code is really doing. Where did this collection with 2056 elements come from? The axWebBrowser.Document itself shouldn't be changing, but its content will be. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.Here you go the full (almost) source code
//Web browser settings this.webBrowser.AddressBar = false; this.webBrowser.Dock = DockStyle.Fill; this.webBrowser.FullScreen = true; this.webBrowser.MenuBar = false; this.webBrowser.Offline = false; this.webBrowser.RegisterAsBrowser = true; this.webBrowser.RegisterAsDropTarget = false; this.webBrowser.Silent = true; this.webBrowser.StatusBar = false; this.webBrowser.TheaterMode = true; . . . private void webBrowser_DocumentComplete (object sender,AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e) { //Test counter - to see how many times this event rised ++this.tempCounter; if ( sender.Equals((object)this.webBrowser) && this.webBrowser.ReadyState.Equals(SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)) { MessageBox.Show ("Done loading\n\nLoaded " + this.tempCounter.ToString() +" times", "Document loaded"); //Receive global Document htmlDocGlobal = (mshtml.IHTMLDocument2) webBrowser.Document; if (clickEvent == null) { //Hook the event if not hooked till now clickEvent = (mshtml.HTMLDocumentEvents2_Event) htmlDocGlobal; clickEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler (On_MouseClick); } } //else // { still loading } } //This function will rise when the user click's on web browser web page private bool On_MouseClick (mshtml.IHTMLEventObj e) { if (e.button.Equals (0)) { //Left-click mouse ArrayList m_PathToElement = new ArrayList(); IHTMLElement m_Parent = null; IHTMLElement m_Child = null; IHTMLElementCollection m_ParentCol = null; IEnumerator colEnum = null; //Receive pre-conditions m_Child = e.srcElement; //TEST_DEBUG: Child element may not have Parent elements !!! m_Parent = m_Child.parentElement; while (m_Child.parentElement != null) //if this is not the root element { { //Get the collection m_ParentCol = (IHTMLElementCollection) m_Parent.all; System.Windows.Forms.Application.DoEvents (); //let the system copy it colEnum = m_ParentCol.GetEnumerator (); colEnum.MoveNext (); //reset to '0' . . . . . Then I go throught collection and search for ckicked element till the root element. } } }
I make some checks for received htmlDocGlobal and the size is different all the time :(( If you need the full source code please contact me by eMail "I have not failed. I've just found 10,000 ways that won't work." - Thomas -
Here you go the full (almost) source code
//Web browser settings this.webBrowser.AddressBar = false; this.webBrowser.Dock = DockStyle.Fill; this.webBrowser.FullScreen = true; this.webBrowser.MenuBar = false; this.webBrowser.Offline = false; this.webBrowser.RegisterAsBrowser = true; this.webBrowser.RegisterAsDropTarget = false; this.webBrowser.Silent = true; this.webBrowser.StatusBar = false; this.webBrowser.TheaterMode = true; . . . private void webBrowser_DocumentComplete (object sender,AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e) { //Test counter - to see how many times this event rised ++this.tempCounter; if ( sender.Equals((object)this.webBrowser) && this.webBrowser.ReadyState.Equals(SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)) { MessageBox.Show ("Done loading\n\nLoaded " + this.tempCounter.ToString() +" times", "Document loaded"); //Receive global Document htmlDocGlobal = (mshtml.IHTMLDocument2) webBrowser.Document; if (clickEvent == null) { //Hook the event if not hooked till now clickEvent = (mshtml.HTMLDocumentEvents2_Event) htmlDocGlobal; clickEvent.onclick += new mshtml.HTMLDocumentEvents2_onclickEventHandler (On_MouseClick); } } //else // { still loading } } //This function will rise when the user click's on web browser web page private bool On_MouseClick (mshtml.IHTMLEventObj e) { if (e.button.Equals (0)) { //Left-click mouse ArrayList m_PathToElement = new ArrayList(); IHTMLElement m_Parent = null; IHTMLElement m_Child = null; IHTMLElementCollection m_ParentCol = null; IEnumerator colEnum = null; //Receive pre-conditions m_Child = e.srcElement; //TEST_DEBUG: Child element may not have Parent elements !!! m_Parent = m_Child.parentElement; while (m_Child.parentElement != null) //if this is not the root element { { //Get the collection m_ParentCol = (IHTMLElementCollection) m_Parent.all; System.Windows.Forms.Application.DoEvents (); //let the system copy it colEnum = m_ParentCol.GetEnumerator (); colEnum.MoveNext (); //reset to '0' . . . . . Then I go throught collection and search for ckicked element till the root element. } } }
I make some checks for received htmlDocGlobal and the size is different all the time :(( If you need the full source code please contact me by eMail "I have not failed. I've just found 10,000 ways that won't work." - ThomasIt looks like you have 2 separate problems. First, test only the part that determines whether the page has finished loading. Once that is ready, then work on those other portions. The simpler you make each test, the easier it is to determine where the problem lies. If you need the complete page and all of its elements to finish loading before you do anything, then you'll need to track each sub-document and note when that has finished as well. Then, when they are all completely loaded, you can do your work. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek. -
It looks like you have 2 separate problems. First, test only the part that determines whether the page has finished loading. Once that is ready, then work on those other portions. The simpler you make each test, the easier it is to determine where the problem lies. If you need the complete page and all of its elements to finish loading before you do anything, then you'll need to track each sub-document and note when that has finished as well. Then, when they are all completely loaded, you can do your work. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.Yeah I thought about - checking all elements in the page for .ReadyState but I don't know how to do it :( Can you show me some code ??? (I check my prog on www.lenta.ru and this web page have 6 frames and 1 pop-up window) "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
-
Yeah I thought about - checking all elements in the page for .ReadyState but I don't know how to do it :( Can you show me some code ??? (I check my prog on www.lenta.ru and this web page have 6 frames and 1 pop-up window) "I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison (1847-1931)
One way to do that would be to add each new document element to a collection when the document state changes. (If your ArrayList doesn't Contain() the document element, then Add() it.) Later, when the state of all those documents is complete, then test to see if you have the information you should have. John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.