title: Invoking an href click event JavaScript in winforms webbrowser control
body: <p>I`m trying to automatically login into one of the online browser games from my application. However when I inspect the login button, I see this html code.</p>
  
  <pre><code>&lt;div id="js_login_button"&gt;
                  &lt;a href="#" onclick="$('#login_submit_button').click()" class="login_button"&gt;
                      &lt;span class="button_left"&gt;&lt;/span&gt;
                      &lt;span class="button_middle"&gt;Login&lt;/span&gt;
                      &lt;span class="button_right"&gt;&lt;/span&gt;
                  &lt;/a&gt;
              &lt;/div&gt;  
  </code></pre>
  
  <p>Since I can`t reach the button's id, I wasn't able to use </p>
  
  <pre><code>webbrowser.Document.GetElementById("button_id").InvokeMember("click");
  </code></pre>
  
  <p>How can I invoke these kind of buttons ?</p>
  
  <p><strong>Edit:</strong> For whom wondering which game is it:
  <a href="https://www.tribalwars.net/" rel="nofollow">https://www.tribalwars.net/</a></p>
  
  <pre><code>&lt;form action="index.php?action=login&amp;amp;show_server_selection=1" method="post" id="login_form" onsubmit="return Index.login_submit();" data-tracked="true"&gt;
      &lt;div&gt;
          &lt;label for="user"&gt;
              &lt;strong&gt;User name:&lt;/strong&gt;
              &lt;span&gt;
                  &lt;input id="user" name="user" class="text" type="text" value="" onkeydown="if((e=window.event||event) &amp;amp;&amp;amp; e.keyCode == 13 &amp;amp;&amp;amp; $('#user').val() &amp;amp;&amp;amp; $('#password').val()) $('#login_form').submit()" data-tracked="true"&gt;
              &lt;/span&gt;
          &lt;/label&gt;
          &lt;label for="password"&gt;
              &lt;strong&gt;Password:&lt;/strong&gt;
              &lt;span&gt;
                  &lt;input name="clear" type="hidden" value="true" data-tracked="true"&gt;
                  &lt;input id="password" name="password" class="text" type="password" onkeydown="if((e=window.event||event) &amp;amp;&amp;amp; e.keyCode == 13 &amp;amp;&amp;amp; $('#user').val() &amp;amp;&amp;amp; $('#password').val()) $('#login_form').submit()" data-tracked="true"&gt;
              &lt;/span&gt;
          &lt;/label&gt;
  
          &lt;input type="submit" id="login_submit_button" style="display: none" data-tracked="true"&gt;
  
          &lt;label for="cookie" class="remember_me"&gt;
              &lt;input id="cookie" type="checkbox" name="cookie" value="true" checked="checked" data-tracked="true"&gt;
                  Remember me
          &lt;/label&gt;
  
          &lt;div id="login-buttons"&gt;
                              &lt;a id="fb-login-button" class="social-login-button" href="https://ipp-facebook.innogames.de/?game=staemme&amp;amp;market=en&amp;amp;" title="Play with Facebook"&gt;&lt;/a&gt;
  
              &lt;div id="js_login_button"&gt;
                  &lt;a href="#" onclick="$('#login_submit_button').click()" class="login_button"&gt;
                      &lt;span class="button_left"&gt;&lt;/span&gt;
                      &lt;span class="button_middle"&gt;Login&lt;/span&gt;
                      &lt;span class="button_right"&gt;&lt;/span&gt;
                  &lt;/a&gt;
              &lt;/div&gt;          
          &lt;/div&gt;
  
          &lt;br style="clear:both;"&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>On this page, the button named <strong>Login</strong> has the same property.</p>
  
  <p>Edit 2: Here is the source code that shows what I tried (and failed):</p>
  
  <pre><code>public Form1()
  {
      InitializeComponent();
      browser.Navigate("https://www.tribalwars.net/"); // browser is defined in the form as a WebBrowser element
  }
  
  private void btnTest_Click(object sender, EventArgs e)
  {
  
      //var debug = browser.Document.GetElementById("login_submit_button").InvokeMember("click"); // there is a runtime null referance error here
  
      var elements = browser.Document.GetElementsByTagName("Login");
  
      foreach (HtmlElement element in elements)
      {
          // The program does not enter here, there is no element !
          //element.InnerHTML to see if it's the one you want
          element.InvokeMember("click");
  
      }
  }
  </code></pre>