title: VB click javascript button/img
body: <p><strong>Hi i am trying to click a button on a website with VB.NET</strong></p>
  
  <p>The Command i use in .AHK is</p>
  
  <pre><code>Pwb.document.getElementsByTagName("IMG")[7].click
  </code></pre>
  
  <p>The button/Img HTML is below.</p>
  
  <pre><code>&lt;img width="34" height="34" style="cursor: pointer;" onclick="doSubmit()" alt="" src="../../images/SC5Login07.jpg" border="0" complete="complete"/&gt;
  </code></pre>
  
  <p>I noticed that it is running a some javascript when its clicked. That is below</p>
  
  <pre><code>function doSubmit() {
              //Submit the form
              if (document.getElementById("txtDBName").value == "") {
              //Login security modifications - End
                  alert('You must select a Database');
              }
              else {
                  if (document.getElementById("txtUserName").value == "") {
                      alert('Please enter your Tesseract user id and password');
                  }
                  else {
                  //Set txtformEvent
                      document.getElementById("txtFormEvent").value = "onSubmit";
                      //Submit the form
                      document.getElementById("frmLoginLaunch").submit();
                  }
              }                   
          }
  </code></pre>
  
  <p>Now i am aware that there is a GetElementById but i cant get that to work due to the lack of an ID. I was hoping it would be as easy as it is in AHK but it is not seeming that way. </p>
  
  <p><em>Basically is there a way to call this dosubmit() function or simulate clicking the image?</em></p>
  
  <p>Hope someone can help
  Thanks</p>
  
  <p><strong>Thankyou Guys this is my login code now</strong></p>
  
  <pre><code>Public Class Form1
  
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      WebBrowser1.Navigate("http://caan/SC5/SC_Login/aspx/login_launch.aspx?SOURCE=ESOLBRANCHLIVE")
  
      While WebBrowser1.ReadyState &lt;&gt; WebBrowserReadyState.Complete
          Application.DoEvents()
      End While
  
      WebBrowser1.Document.GetElementById("txtUserName").SetAttribute("value", "kieranw")
      WebBrowser1.Document.GetElementById("txtPassword").SetAttribute("value", "kieranw")
  
      Dim allImgTags As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
      If allImgTags IsNot Nothing Then
          For Each img As HtmlElement In allImgTags
              If img.GetAttribute("src").Contains("/images/SC5Login07.jpg") Then
                  img.InvokeMember("Click")
                  Exit For
              End If
          Next img
      End If
  
  End Sub
  </code></pre>
  
  <p>End Class</p>