title: How to click HTML button programatically by vb.net
body: <p>I am trying to click a button programatically . The button is on the 3rd page of the website. and it does not have any id . It has just name , type and value . The HTML code of the button is given below</p>
  
  <pre><code>&lt;FORM NAME='form1' METHOD='post' action='/dflogin.php'&gt;
  &lt;INPUT TYPE='hidden' NAME='txtId' value='E712050-15'&gt;
  &lt;INPUT TYPE='hidden'NAME='txtassId' value='1'&gt;
  &lt;INPUT TYPE='hidden' NAME='txtPsw' value='HH29'&gt;
  &lt;INPUT TYPE='hidden' NAME='txtLog' value='0'&gt;
   &lt;h6 align='right'&gt;
   &lt;INPUT TYPE='SUBMIT' NAME='btnSub' value='Next' style='background-color:#009900;    color:#fff;'&gt;&lt;/h6&gt;&lt;/FORM&gt; 
  </code></pre>
  
  <p>I have tried these codes in vb.net 2008 express edition...</p>
  
  <pre><code>For Each webpageelement As HtmlElement In allelements
  
              If webpageelement.GetAttribute("value") = "Next" Then
  
                  webpageelement.InvokeMember("click")
  
              End If
          Next
  </code></pre>
  
  <p>And 2nd one</p>
  
  <pre><code>theElementCollection = WebBrowser1.Document.GetElementsByTagName("INPUT")
  
      For Each curElement As HtmlElement In theElementCollection
  
          ctrlIdentity = curElement.GetAttribute("innerText").ToString
  
          If ctrlIdentity = "Next" Then
  
              curElement.InvokeMember("click")
  
          End If
  
      Next
  </code></pre>
  
  <p>and 3rd one is</p>
  
  <pre><code>      Dim l_forms = WebBrowser1.Document.GetElementsByTagName("form")
          If l_forms.Count &gt; 0 Then
              l_forms.Item(0).InvokeMember("submit")
          End If
  and 4th one is
  
  Do While WebBrowser1.ReadyState &lt;&gt; WebBrowserReadyState.Complete
  Application.DoEvents()
  Loop
  WebBrowser1.Document.Body.InnerHtml = Replace(WebBrowser1.Document.Body.InnerHtml,"NAME='btnSub'", "NAME='btnSub' id='btnSub'") 'insert id into youre button
  WebBrowser1.Document.GetElementById("btnSub").InvokeMember("click") 'click on btnSub
  </code></pre>
  
  <p>and the last one is</p>
  
  <pre><code>Dim i As Integer
          Dim allButtons As HtmlElementCollection
  
          allButtons = WebBrowser1.Document.GetElementsByTagName("input")
  
          i = 0
          For Each webpageelement As HtmlElement In allButtons
              i += 1
              If i = 5 Then
                  webpageelement.InvokeMember("click")
              End If
          Next
  </code></pre>
  
  <p>These all codes are unable to click that button. Kindly Please Suggest a appropriate solution for clicking this button. Thank You So Much</p>