0

The StatusTextChanged event in the c# webbrowser says Done multiple times, 31 to be precise, I see that is almost as much as the sum of the x's in "downloading x resources".

How can I know when it's really done? Or if this isn't possible how can I know when a specific element has rendered.

There are other similar questions online but only with half working hackey results.

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
BinkyNichols
  • 586
  • 4
  • 14

1 Answers1

0

Thanks @Golda,

The exact answer you linked didn't work as loading is not asynchronous, if you add a periodic pause, the webbrowser won't keep loading. The reply marked as answer on that thread wasn't what I asked for, but combining the two answers got me what I was looking for, Code to check every n seconds whether or not a certain tag with certain attributes was rendered.

  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;
            }
        }
BinkyNichols
  • 586
  • 4
  • 14
  • Please check this link. This article explains how to retrieve the frame element. http://blog.vivensas.com/extract-the-value-from-the-frame-element-c/ – Golda Oct 09 '19 at 11:07
  • sorry solved this months ago, should make an answer, uses alot of recursion and custom events – BinkyNichols Oct 10 '19 at 13:54