LeChuck LeChuck - 1 month ago 5x
PowerShell Question

Using Powershell, I want to select an automatically opened .net web application as an object

So I'm in the early days of setting up some automated testing, and I'm using powershell ISE to open a url, then select a button.

$ie = New-Object -com "InternetExplorer.Application"
$ie.visible = $true
sleep 30

This will automatically open a new .net application in a separate window. I now want the code to automatically select a button on this newly opened window.

Is there a way for me to create a new object using the new application window, without having to specify the url address?

If I try and simply link straight to the application's url, it recognizes that this is not a new session and won't let me access it.


Use Shell.Application COM object to enumerate [Internet] Explorer windows and check LocationURL:

$shellApp = New-Object -com Shell.Application
$ie2 = $shellApp.Windows() | ?{ $_.LocationURL -like "http://otheraddress*" }

Now $ie2 contains IE document for that other address (or an array if many matching urls exist).