title: Powershell Script to click on an onclick img alt HTML element on website
body: <p>I am trying to get my powershell script to click on the following object on a website.</p>
  
  <p><strong><em>Source Code:</em></strong></p>
  
  <pre><code>&lt;a onclick="document.selectAccountsGroupsForm.action='manageAccountsGroups.do?method=showAllAccounts';document.selectAccountsGroupsForm.submit();"&gt;
     &lt;img alt="showAllAccounts" src="/TNE/images/common/buttons/btn_showAllAccounts.gif"&gt;
  &lt;/a&gt;
  &lt;input name="accountSelectionCBChecked" type="hidden" value="false"&gt;
  </code></pre>
  
  <p><strong>Powershell Code</strong></p>
  
  <pre><code>$ie = new-object -Com InternetExplorer.Application;
  $ie.visible = $true;
  $ie.navigate($url);
  while($ie.busy) {Start-Sleep -Milliseconds 1000;}
  
  $ie.Document.getElementById(“userName”).value = $Username 
  $ie.Document.getElementByID(“password”).value = $Password 
  $ie.Document.getElementById(“loginBtn”).Click()
  $link=$ie.Document.getElementsByTagName('A') | Where-Object {$_.href -eq "document.selectAccountsGroupsForm.action='manageAccountsGroups.do?method=showAllAccountGroups';document.selectAccountsGroupsForm.submit();"}
  $link.click()
  </code></pre>
  
  <p>Note: Username, Password, and URL Variables are not posted</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>You cannot call a method on a null-valued expression. 
  At H:\Desktop\Scripts\TEST.ps1:56 char:1 
  + $link.click() 
  + ~~~~~~~~~~~~~ 
      + CategoryInfo : InvalidOperation: (:) [], RuntimeException 
      + FullyQualifiedErrorId : InvokeMethodOnNull –
  </code></pre>