title: Powershell - click on a href link within div
body: <p>I'm sure this must have been answered before but I guess I just don't know what I should be using in my search terminology.</p>
  
  <p>I'm trying to get powershell to click on a simple 'a href' link. But all the powershell examples I've found for clicking on things so far are using buttons. when I try to rewrite the button-clicking scripts to click on the link instead I'm getting a "You cannot call a method on a null-valued expression" error message.</p>
  
  <p>The source for the link I want to click is:</p>
  
  <pre><code>    &lt;div id="reportTreer1r3" style="padding-left:32px;" uid="2.-83016" nowrap 
      class="treeNode" onClick="reportTree.onSelect('r1r3');" onDblClick="reportTree.onDblSelect('r1r3');
      " BP_REPORT_ID="-83016" reportType="report" isRemovable="false"&gt;
      &lt;nobr&gt;
        &lt;a href="#r1r3" onClick="return false;" onKeyDown="reportTree.onKeyDown(this);"&gt;
          &lt;span&gt;
            &lt;label class="hidden-label"&gt; Tree level 1, 4 of 4. &lt;/label&gt;
            &lt;span&gt;Adherence Summary&lt;/span&gt;
          &lt;/span&gt;
          &lt;label name="SelectInfo" class="hidden-label"&gt;&lt;/label&gt;
        &lt;/a&gt;
      &lt;/nobr&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Unfortunately the link hasn't been given an element id of its own so I can't just "getElementByID" on it, instead I've tried a bunch of things along the lines of...</p>
  
  <pre><code>    $link = $doc.getElementsByTagName('a') | Where-Object {$_.href -eq '#r1r3'} 
      $link.click() 
  </code></pre>
  
  <p>... but none of it seems to be working. </p>
  
  <p>Any suggestions would be much appreciated!</p>