1

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

Jon Warren
  • 857
  • 6
  • 18
  • 1
    are you running the powershell session as admin? i think what is happening here is that you are losing the handle to your ie after calling navigate (has to do with different integrity levels: https://msdn.microsoft.com/en-us/library/bb625962.aspx?f=255&MSPPError=-2147217396), try running the script as admin – Paul Feb 02 '17 at 17:11
  • 1
    This might be helpful: http://stackoverflow.com/questions/13869518/powershell-ie9-comobject-has-all-null-properties-after-navigating-to-webpage – Paul Feb 02 '17 at 17:22

0 Answers0