I'm trying to write a simple PowerShell script that navigates to a page, waits for it to load and then performs tasks.
I've seen many examples make use of "$ie.Busy" in order to check if the page is ready, but that's not working for me.
Here is the bare-bones of what I'm trying to do:
$ie = new-object -ComObject "InternetExplorer.Application";
$ie.visible = $true;
$ie.navigate("www.some-page.com");
while ($ie.Busy -eq $true)
{
sleep -Milliseconds 100;
}
//do stuff
However, $ie.Busy is not working the way I believe that it is supposed to. It doesn't ever enter the while loop, as I found out by including a print statement within the loop and not seeing it print anything. Trying to print the contents of $ie.Busy after navigation just returns "System.__ComObject.Busy".
I also tried changing my while loop to this:
If ($ie.Busy -eq $true) {"True"}
ElseIf ($ie.Busy -eq $false) {"False"}
Else {"Neither"}
in order to see what the value of $ie.Busy is. It would just print "Neither" so it doesn't pick up a Boolean value as expected. Is there any way to wait for the page to load?
NOTE: I've also seen people use ReadyState as an alternative, but it gives me the same problem that Busy does in the sense that it doesn't return an integer when I try to access its value.
*Using IE11