Browsing IE via its COM object in Powershell

108 Views Asked by At

I've written a Powershell script to automate a Web UI test using IE. The script runs fine when I execute it from PowerShell. However, I have run into an obscure problem and that is when I run my Web UI test script from another powershell script, it fails. I tried to debug it and found that it fails on the following line.

$button = $ie.Document.getElementsByTagName("button") $button.Item().Click() # $button.Item() evaluates to null when the script is executed from another script.

Can anyone help me figure this out? It appears that when I run the script, the script has no issues locating the element, but when it is run from another script the element I am looking for cannot be located.

EDIT I get the same error when I run the PS script through Task Scheduler. The script only works when I invoke it directly. If I invoke via another script/program, it doesn't work.

0

There are 0 best solutions below