开发者

How to wait for axWebBrowser to finish loading?

开发者 https://www.devze.com 2023-02-17 03:52 出处:网络
I am using axWebBrowser to do some web automation. When the system triggers the NewWindow2 event, it is unable to开发者_JS百科 keep track of an HTML element in the new window. After debugging, I notic

I am using axWebBrowser to do some web automation. When the system triggers the NewWindow2 event, it is unable to开发者_JS百科 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号