title: VBA IE Automation without ID or Name
body: <p>I am trying to use VBA to automate input of Username/Password on a form that doesn't have any ID or Name to it.   Is this possible?</p>
  
  <p>Have a look at the <a href="https://cis.mesaaz.gov/eservices/p_template" rel="nofollow">sample webpage</a>.  This webpage doesn't work with the names from what I can tell.   </p>
  
  <p>VBS code:</p>
  
  <pre><code>uname = "myusername"
  pword = "mypassword"
  
  Set objIE = CreateObject("InternetExplorer.Application")
  WebSite = "https://cis.mesaaz.gov/eservices/p_template"
  With objIE
    .Visible = True
    .Navigate WebSite
      Do While .Busy Or .ReadyState &lt;&gt; 4
          DoEvents
      Loop
  
      Set element = .Document.getElementsByName("userid")
      element.Item(0).Value = uname
  
      Set element = .Document.getElementsByName("ping")
      element.Item(0).Value = pword
  
      Set element = .Document.getElementsByName("submit")(0)
      element.Click
  
      Do While .Busy Or .ReadyState &lt;&gt; 4
          DoEvents
      Loop
  
  End With
  </code></pre>
  
  <p>Form HTML code:</p>
  
  <pre><code>&lt;form action="uwpqutil.p_VALLOGIN" method="POST" target="_top" name="Login"&gt;
  &lt;center&gt;
  &lt;table border="0" cellpadding="3" cellspacing="0"&gt;
  &lt;tbody&gt;&lt;tr&gt;
  &lt;td rowspan="1" colspan="3" align="LEFT"&gt;&lt;b&gt;Log-In&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td valign="middle"&gt;&lt;b&gt;UserName&lt;/b&gt;&lt;/td&gt;
  &lt;td valign="middle"&gt;&lt;input name="userid" size="30" type="text"&gt;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td valign="middle"&gt;&lt;b&gt;Password&lt;/b&gt;&lt;/td&gt;
  &lt;td valign="middle"&gt;&lt;input name="pin" size="30" type="password"&gt;&lt;/td&gt;
  &lt;input name="JavaScript" value="enabled" type="hidden"&gt;
  &lt;script language="JavaScript"&gt;&lt;!--
  document.Login.JavaScript.value = 'enabled';
  //--&gt;&lt;/script&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td valign="middle" align="right"&gt;&lt;input value="Log-In" type="submit"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;
  &lt;/center&gt;
  &lt;/form&gt;
  </code></pre>