简体   繁体   中英

C# wait for page loading (web browser)

I am new to C # , so I am sorry if this question is stupid. I'm trying to do some automation using web browser winforms control.

to check the download status I use ReadyState:

while (browser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }

i get the value Complete in WebBrowserReadyState but the page does not load completely, as it contains charts.

How to wait for example 2 seconds, , to load all the elements on a web page? I use windows 10 IE 11.

  using (WebBrowser browser = new WebBrowser()) { browser.Width = width; browser.Height = height; browser.ScrollBarsEnabled = true; Uri uri = new Uri(Mon_URL); string additionalHeaderInfo = "Authorization: Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password)) + System.Environment.NewLine; browser.Navigate(uri, null, null, additionalHeaderInfo); while (browser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } } Application.Exit(); 

while ( browser.ReadyState != WebBrowserReadyState.Complete ) { Application.DoEvents(); }

i get the value Complete in WebBrowserReadyState but the page does not load completely, as it contains charts.

How to wait for example 2 seconds, , to load all the elements on a web page? I use windows 10 IE 11.

Please check the condition. The WebBrowserReadyState.Complete status means the control has finished loading the new document and all its contents. if you want to wait all elements load success, you could change the condition from "!=" to "==", like this:

while (browser.ReadyState == WebBrowserReadyState.Complete) {
Application.DoEvents(); }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM