Hi Scripters! I’m working with Internet Explorer automation to launch and log on to two websites. I can successfully create the IE COM objects, pass them to a “login” function, and see that the site accepts the credentials. However, afterward I would like to periodically refresh the page in order to maintain the session. When I pass the existing IE objects to my “test-loginPage” function (designed to check if we’re back at the login page, and either login again else refresh the current page), I consistently get the InvokeMethodOnNull error when trying to use the object’s Refresh method. If I use the ISE debugger and put a breakpoint at the beginning of the test-loginPage function, I can verify that the object has been passed to the function, that it’s still an IE object, and that Get-Member indicates it has a Refresh method. What am I doing wrong?
Here’s the Gist; I’m running Windows 10.1511, so Powershell 5 interacting with IE 11.
Note: I did change the stored logon information so that it is not valid credentials, and therefore commented out the part of the test-loginPage function that would normally be checking if we’re still on the login page. I still expect the code to fill in the login fields but I expect the site in question will fail the logon attempt.
Yes, same error. Also the same if I directly call the refresh method of the $ieTS/$ieTex objects instead of passing them to the test-logonPage function.
If I write out just the “launch website and refresh it” part, it works, as in:
Launches 2 IE windows, loads the appropriate pages, waits, and successfully refreshes both.
BUT, running only the “start-IE” function (logon still commented out) and then calling the refresh method on the returned object fails, even if I launch only a single page. So, if I pull just this out of the script and run it, I get the error:
…Something about transporting the IE object out of the function? I still get what looks like the object if I ask for $ieTex after running the above code:
PS C:\Users\jflanagan> $ieTex
Okay, that was pretty simple and it works for refreshing the page. Thanks 84rusty!
Can you point me at an explanation of when/why I would need to use the .Application part? I’d like to learn and so far I’m failing at searching for it.