1

I am using axWebBrowser to do some web automation. When the system triggers the NewWindow2 event, it is unable to keep track of an HTML element in the new window. After debugging, I noticed that the axWebBrowser1.ReadyState is equal to ReadyState_Complete although the new window hasn't finished loading.

private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e) {            
    if (axWebBrowser1.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) {
        // some code...
    }
}

How can I wait for the new window to finish loading so I can detect the HTML element in it?

Jon
  • 4,925
  • 3
  • 28
  • 38
DEN
  • 1,893
  • 7
  • 27
  • 51

1 Answers1

1

I think you can handle the ProgressChanged event:

private void webBrowser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)  
{  
  siteLoading.Value = (int)e.CurrentProgress;
  if (e.CurrentProgress >= e.MaximumProgress)
  {
    // Loaded.
  }
}  

Take a look the the following questions:
http://www.vbforums.com/showthread.php?t=526871
http://social.msdn.microsoft.com/Forums/en/ieextensiondevelopment/thread/8785ddcc-6f48-410b-8cd4-122b3f2b0e34

Kamyar
  • 18,639
  • 9
  • 97
  • 171
  • thanks for your fast reply kamyar. The code that you provide is not working because i'm using axWebBrowser (Com component)... – DEN Mar 17 '11 at 06:01
  • @Den: It seems like handling DocumentComplete event id the standard way. look at: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22598363.html and http://www.vbforums.com/showthread.php?t=557963 and http://www.experts-exchange.com/Programming/Misc/Q_21043365.html – Kamyar Mar 17 '11 at 06:07
  • Google the address, navigate to the bottom of the page, you'll see the result. – Kamyar Mar 17 '11 at 06:12
  • Try this link: http://www.google.com/#hl=en&sugexp=gsihc&xhr=t&q=http%3A%2F%2Fwww.experts-exchange.com%2FProgramming%2FLanguages%2F.NET%2FVisual_Basic.NET%2FQ_22598363.html&cp=91&pf=p&sclient=psy&site=&source=hp&aq=f&aqi=&aql=&oq=http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22598363.html&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=23daeab4d2e2d925 can you view now? – Kamyar Mar 17 '11 at 06:23
  • Hmm. strange. Have you scrolled to the very bottom? it shows you the subscription message, but you can see the result at the end. – Kamyar Mar 17 '11 at 06:55
  • What i saw after i have scrolled to the very bottom is the message left by VBRocks and Kanus. VBRocks's answer is not working for me. It is only working for WebBrowser but not AxWebBrowser. I'm facing the problem of axWebBrowser1.ReadyState is equal to ReadyState_Complete although the AxWebbrowser hasn't load finish. Therefore,i'm looking for other solution. Kamyar,do you have any idea? – DEN Mar 17 '11 at 07:17