title: PowerShell fill up form and submit
body: <p>I need to fill up a form of an internal site. I was able to successfully login to the portal page using this code</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$ie = New-Object -Com InternetExplorer.Application 
  $ie.Visible = $true
  $ie.Navigate("https://some-internal-ip/login") 
  while ($ie.ReadyState -ne 4) {Start-Sleep -m 100};
  
  #Login 
  $form = $ie.document.forms[0]
  $inputs = $form.GetElementsByTagName("input")
  ($inputs | where {$_.Name -eq "username"}).Value = $username
  ($inputs | where {$_.Name -eq "password"}).Value = $password
  ($inputs | where {$_.Name -eq "action:Login"}).Click()
  
  #after login - navigate to this link
  while ($ie.ReadyState -ne 4 -or $ie.Busy) {Start-Sleep -m 100}
  Start-Sleep -m 2000
  $ie.Navigate("https://some-internal-ip/monitor/users")
  </code></pre>
  
  <p>Above works fine. It'll direct me to the new link where I need to fill another form. So I'm reusing my code above to fill up a form for a <strong>user field</strong> and <strong>submit button</strong>.</p>
  
  <p>There are multiple forms inside this page so I want to narrow it down to this specific <code>id="trackingSearchForm"</code>.</p>
  
  <p>HTML form:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form action="https://.../" method="POST" name="trackingSearchForm" id="trackingSearchForm" accept-charset="utf-8" onsubmit="return false;"&gt;
  &lt;input name="user" onkeypress="keyPressHandler(this.form, event)" class="" type="text" id="user" value="&gt;
  &lt;input type="button" class="submit" id="submitButton" value="Search" onclick="performSearch();"&gt;
  </code></pre>
  
  <p>Get ID of form and fill up</p>
  
  <pre class="lang-bsh prettyprint-override"><code>while ($ie.ReadyState -ne 4 -or $ie.Busy) {Start-Sleep -m 100}
  $form =  $ie.Document.Forms[0]
  $form = ($ie.Document.Forms[0] | where {$_.Id -eq "trackingSearchForm"})
  $inputs = $form.GetElementsByTagName("input")
  ($inputs | where {$_.name -eq "user"}).Value = "john"
  ($inputs | where {$_.Id -eq "submitButton"}).Click()
  </code></pre>
  
  <p>but I'm getting these errors:</p>
  
  <pre>
  You cannot call a method on a null-valued expression.
  + $inputs = $form.GetElementsByTagName("input")
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull
  
  The property 'value' cannot be found on this object. Verify that the property
  exists and can be set.
  + ($inputs | where {$_.Name -eq "user"}).Value = "john"
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
      + FullyQualifiedErrorId : PropertyNotFound
  </pre>
  
  <p>The same code I used for the login form doesn't work on another form.</p>