views:

1114

answers:

3

Hey all.

I want to ask about manipulating IE via Powershell. My goal is to write script that will automatically perform some actions in the browser (on the client side – navigate to page, perform actions, measure time between responses, etc.)

I have this little thing:

$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate("http://google.com")

Now I want to check whether the browser stopped page rendering (assuming, that google takes like 30 seconds to load). As I checked with $ie | get-member there is DocumentCompleted property (event), but I don’t know how to access/compare it. How should I do that?

Or maybe I should use .NET instead COM object and initiate $ie with [system.Windows.Forms.WebBrowser] ?

cheers

edit:
Well... $ie.busy works, but (what maybe I haven't made clear earlier) I want to know exact moment of the page rendering competition. Checking $ie.busy in infinite loop every second might work but I suppose it's not the best way to do that.

Let's say page is loading some time (rendering is long due to the gigantic scripts on client side). I would like how long does it take to:

  1. load page
  2. how long it will take to reload/re-render after changing some data and clicking 'Save'.
A: 

You can check .busy property.

edit:

Status property will also work here. However you can use tool like Firebug to see page load time.

testmann
For now I will stick with .busy, although PS Even Library proposed by Jason is something worth look into. Firebug is not the case, as I want to load page about 1000 times and see the average load time.
yoosiba
+1  A: 

If you do decide to go .NET instead of PowerShell, WatiN is great for this. It will give you tons of flexibility over the WebBrowser control and is a lot easier to use. You can also drive Firefox now in version 2.

Adam Neal
You will have to use Powershell V2 with WatiN, as WatiN needs STA
James Pogran
Later (just for fun) I used WatiN with C# and it was great. Thanks for that hint!
yoosiba
A: 

Since it has an event, you could try out the PowerShell Eventing Library. It says that it supports COM events, though I haven't tried it.

JasonMArcher