-1

Wondering if it is possible to select an IE window based on the HWND property (or similar). My script clicks a link which opens a new page in a separate window and I would like to be able to work with this new window.

Here is my code:

$ie.Navigate("https://chaseloanmanager.chase.com/Chaselock/ViewOnlineGuide.aspx") # opens page in new window
while ($ie.Busy -eq $true){Start-Sleep -Seconds 2}

$childWindow = Get-Process | Where-Object {($_.ProcessName -eq 'iexplore')} | Get-ChildWindow | Where-Object {$_.ChildTitle -match 'Lending'} 
$childWindow.MainWindowHandle # gets HWND of new window

$shell = New-Object -ComObject Shell.Application
$ie3 = $shell.Windows() | Where-Object {$_.HWND -match $childWindow.MainWindowHandle} # does not find window
Eric Furspan
  • 742
  • 3
  • 15
  • 36
  • What do you mean by "work with"? You want to focus on the new window or do you want to use `InternetExplorer.Application` comobjects to control it? – Frode F. May 02 '16 at 16:06
  • I want to use the `InternetExplorer.Application` comobject to control the new window – Eric Furspan May 02 '16 at 16:08

1 Answers1

1

You can get the IE comobject by searching through Windows() in Shell.Application.

$shell = New-Object -ComObject Shell.Application

$ie = $shell.Windows() | Where-Object { $_.LocationURL -match 'Lending' }
#$ie = $shell.Windows() | Where-Object { $_.HWND -eq 2951084 }

$ie.Navigate("http://www.stackoverflow.com")
Frode F.
  • 52,376
  • 9
  • 98
  • 114
  • Thanks, unfortunately I can't get my code to work as expected. Adding my code to original post. – Eric Furspan May 02 '16 at 16:22
  • Did you try using `LocationName` (title of website) or `LocationURL` (if you know parts of the url that's unique to the one you want)? Then you could skip the hwnd-search++ all together. Ex. see updated answer – Frode F. May 02 '16 at 16:27
  • Have you tried just `$shell.windows()`? The. You can find what to search for. If it's missing then your out of luck. – Frode F. May 02 '16 at 16:38
  • Yea, so when I just use `$shell.windows()`, nothing returns to the console. however when I ask for the `count` it returns `1`. Odd... – Eric Furspan May 02 '16 at 16:44