title: How do I click submit on a popup window with Powershell?
body: <p>I have been attempting to teach myself programming. This is the first time I have tried to use any scripting at my day job. I'm trying to write a script to pull a report from a webapp. I've got it to work all the way to the very end. It will open IE, log me in, navigate to the reports page, but then once it clicks the report button, a popup window appears. I just need it to click Submit. Here is the popup window:</p>
  
  <p><a href="https://i.stack.imgur.com/HOoZe.png" rel="nofollow noreferrer">Popup Window</a></p>
  
  <p>Why is the script not working? The element should be inside IE.document correct? The screenshot below shows that the ID of the Submit button is "submit".</p>
  
  <p><a href="https://i.stack.imgur.com/7iB9H.png" rel="nofollow noreferrer">Inspect Element of the submit button</a></p>
  
  <p>This is the error powershell gives me: </p>
  
  <pre><code>You cannot call a method on a null-valued expression.
  At C:\Users\snewhous\Documents\test.ps1:38 char:44
  + $IE.Document.getElementById("submit").click &lt;&lt;&lt;&lt; ()
      + CategoryInfo          : InvalidOperation: (click:String) [], RuntimeException
      + FullyQualifiedErrorId : InvokeMethodOnNull
  </code></pre>
  
  <p><br>
  Code:</p>
  
  <pre><code>$Username = "myusername"
  $Password = "mypassword"
  
  $IE=new-object -com internetexplorer.application
  $IE.navigate2("website.com")
  $IE.visible=$true
  
  while ($IE.Busy -eq $true) 
  { 
  Start-Sleep -Milliseconds 2000; 
  } 
  
  $IE.Document.getElementById("loginId").value = $Username 
  $IE.Document.getElementById("password").value = $Password 
  $IE.Document.getElementById("loginButton").click() 
  
  while ($IE.Busy -eq $true) 
  { 
  Start-Sleep -Milliseconds 5000; 
  }  
  
  $IE.navigate2("https://eams.mymxportal.com/adHoc/adHoc/manageAdHoc?1")
  
  while ($IE.Busy -eq $true) 
  { 
  Start-Sleep -Milliseconds 5000; 
  }  
  
  $IE.Document.getElementById("id3b6").click() 
  
  while ($IE.Busy -eq $true) 
  { 
  Start-Sleep -Milliseconds 5000; 
  }
  
  $IE.Document.getElementById("submit").click()
  </code></pre>
  
  <p>Any input is appreciated!
  Thanks so much!</p>