首页 > 解决方案 > C# Webbrowser/IE 状态栏显示“完成”时间,完成的真正含义是什么?

问题描述

c# webbrowser 中的 StatusTextChanged 事件多次表示完成,准确地说是 31 次,我看到这几乎与“下载 x 资源”中 x 的总和一样多。

我怎么知道什么时候真的完成了?或者,如果这不可能,我怎么知道特定元素何时呈现。

网上还有其他类似的问题,但只有一半有效的hackey结果。

status 
status 
status 
status 
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Waiting for https://www.google.com/maps/search/restaurants%20in%20Mahé%20Seychelles...
status Done
status (7 item(s) remaining) Downloading picture https://www.google.com/images/branding/mapslogo/1x/googlelogo_62x24_with_2_stroke_color_66x26dp.png...
status Done
status (24 item(s) remaining) Downloading picture https://maps.gstatic.com/tactile/icons/pane-info-6fe7b51d16ef9c34e2c80167eb77e587.png...
status Done
status Done
status (3 item(s) remaining) Downloading picture https://maps.gstatic.com/tactile/runway/icon-add-photo-1x.png...
status Done
status Done
status (3 item(s) remaining) Downloading picture 
https://maps.gstatic.com/tactile/mylocation/mylocation-sprite-cookieless-v2-1x.png...
status Done
status Done
status Done
status Downloading picture https://maps.gstatic.com/tactile/pegman_v3/default/runway-1x.png...
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done
status Done

标签: c#webbrowser-control

解决方案


谢谢@Golda,

您链接的确切答案不起作用,因为加载不是异步的,如果您添加定期暂停,网络浏览器将不会继续加载。在该线程上标记为答案的回复不是我所要求的,但结合这两个答案让我得到了我想要的东西,代码每隔 n 秒检查是否呈现了具有某些属性的某个标签。

  private void button1_Click(object sender, EventArgs e)
        {
            Navigate n = new Navigate();
            n.Done += delegate
            {
                MessageBox.Show("");
            };
    //wb is the webbrowser, nav is the url
            n.Wait(wb, nav, 1);

        }

        public class Navigate
        {
            public delegate void NavigateDoneEvent();
            public event NavigateDoneEvent Done;

            private Timer wait;
            HtmlElement e2 = null;

            public void Wait(WebBrowser Browser, string Url, double Seconds)
            {
                Browser.Navigate(Url);

                wait = new Timer();
                wait.Interval = Convert.ToInt32(Seconds * 1000);

                wait.Tick += (s, args) =>
                {
                    if (Form1.wb.Document != null)
                    {
                        HtmlElementCollection c1 = Form1.wb.Document.GetElementsByTagName("element tag type");

                        foreach (HtmlElement e3 in c1)
                        {
                            if (e3.GetAttribute("className") == "class name")
                            {
                                if (e3.InnerText.Contains("something"))
                                {
                                    e2 = e3;
                                    wait.Enabled = false;
                                    MessageBox.Show(e2.InnerText);
                                    Done();
                                }
                            }
                        }
                    }
                };

                wait.Enabled = true;
            }
        }

推荐阅读