title: How to reference content in a frame in new window with PowerShell?
body: <p>I'm using PowerShell to login to a web app.  Upon logging in, the app opens a new window.  The new window has a frameset with three frames.  I'm trying to click a link in one of the frames ("Left").</p>
  
  <pre><code>$ie = New-Object -ComObject "InternetExplorer.Application"
  $ie.navigate("http://example.local")
  while($ie.ReadyState -ne 4) { Start-Sleep -Seconds 5 }
  $ie.visible = $true
  $doc = $ie.document
  
  $userField = $doc.getElementById("uid")
  $passwordField = $doc.getElementById("pwd")
  $submitButton = $doc.getElementById("submit")
  
  $userField.value = "userid"
  $passwordField.value = "*****"
  $submitButton.click()
  
  $shell = New-object -ComObject "Shell.Application"
  # The app opens a new window with a timestamp - that's the window I want, so I skip the other window
  $ie2 = $shell.Windows() | where {$_.Type -eq "HTML Document" -and $_.LocationName -ne "My App - Parent Window"}
  $doc2 = $ie2.document
  $frames = @($doc2.getElementsByTagName("FRAME"))
  Write-Host $frames.Count # shows "3"
  Write-Host $frames[1].Title # shows "Left Nav"
  </code></pre>
  
  <p>How do I reference the Left frame?  I've tried various combinations that I thought would work, mostly some variation of <code>$frames[1].document.something...</code>.</p>
  
  <p>The HTML (not my code):</p>
  
  <pre><code>&lt;frameset rows="60,*"&gt;
      &lt;frame src="http://example.local/really/long?url" title="Top Nav" name="Top" id="Top"&gt;
      &lt;frameset cols="175,*"&gt;
          &lt;frame src="http://example.local/left.html" title="Left Nav" name="Left" id="Left"&gt;
          &lt;frame src="http://example.local/main.html" title="Main Display" name="Main" id="Main"&gt;
      &lt;/frameset&gt;
  &lt;/frameset&gt;
  </code></pre>
  
  <p>Instead of using the $frames array, I used the frames property as suggested by @Adi.</p>
  
  <pre><code>$frames = $doc2.frames
  $left = $frames.item([ref]1).document      # the frame I need
  $left_frames = $left.frames                # this page has frames too
  $nav = $left_frames.item([ref]0).document  # the frame I need
  $nav.body.outerHTML                        # gives me the code I need
  </code></pre>