I found this thread really helpful and ended up coming up with a slightly different solution. I am pretty new to powershell so hopefully I didn't make a hash of it but this worked really well for me.
I used a "while" statement so that my condition would loop while true:
while($ie.document.body.outerHTML -notMatch "<input type=`"submit`" value=`"Continue`">") {start-sleep -m 100};
In this case I was matching against a portion of the "outerHTML" part of the body. As long as I don't match the specified text the script will wait and continue to loop the match check.
I like this solution as I could do it in more or less one line of code and I like to keep things compact where possible. Hopefully this is helpful to someone else. Like the OP I found ie.readystate to be very finnicky/unreliable but I really didn't want to just put a static sleep timer in.
Also, while Chrome is an excellent way to break a page down. You can also print to the console window once you have IE running programmatically by simply running:
$ie.document.body
You can dig through visually and then filter down to the section you want which should speed up your matching (I would guess), which is what I did in my code example above.
The only other thing I will note... I think -match uses "regex" because I had to use the tick mark (ex. ` ) to escape the quotes that were part of the string I was matching.
Cheers!
Here is a good reference on "while" logic:
http://www.powershellpro.com/powershell-tutorial-introduction/logic-using-loops/
InternetExlporer.Application
COM object? If so, you probably will not be able to subscribe for events, because it's not a .NET object. If it were a .NET object, you could useRegister-ObjectEvent
to hook up an event handler.break
statement inside thewhile
loop.