title: Click on html element (by class) using WebBrowser c#
body: <p>My code is:</p>
  
  <pre><code> WebBrowser browser = new WebBrowser();
              browser.Navigate("http://myurl");
              var links = browser.Document.GetElementsByTagName("a");
              foreach (HtmlElement link in links)
              {
                  if (link.GetAttribute("class") == "expand-chain no-tracks")
                  {
                      MessageBox.Show("Click here");
                      link.InvokeMember("click");
                  }
              }
  </code></pre>
  
  <p>And i need to get all html elements with "expand-chain no-tracks" class and after i need to click on it.</p>
  
  <p>My problem is that i always get a NullReferenceException for reason "object reference not set to an istance of an object".</p>
  
  <p>Html code is:</p>
  
  <pre><code>&lt;a class="expand-chain no-tracks" data-chain-id="ZYZ" href="#" style="display: none;"&gt;
  &lt;span&gt;
  Some text
  &lt;/span&gt;
  &lt;/a&gt;
  </code></pre>
  
  <p>Please help me!
  Thanks</p>
  
  <p><strong>EDIT</strong>
  I tried also with this code but it never execute browser_DocumentCompleted function</p>
  
  <pre><code> public void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
          {
              WebBrowser browser = sender as WebBrowser;
              var links = browser.Document.GetElementsByTagName("a");
  
                  foreach (HtmlElement link in links)
                  {
                      if (link.GetAttribute("class") == "expand-chain no-tracks")
                      {
                          MessageBox.Show("Here");
                          link.InvokeMember("click");
                      }
                  }
          }
  
          public void cazz()
          {
              WebBrowser browser = new WebBrowser();
              browser.Navigate("http://myurl");
              browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
          }
  </code></pre>