0

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.

user6037143
  • 516
  • 5
  • 20
  • It is also possible that object value for button not assigned properly, When you try to invoke it via any other script. You can try to provide both sample script and that other script in which you have invoked this script. We will try to check if there is any issue in it or not and try to find a possible solution. – Deepak-MSFT Nov 28 '18 at 07:54
  • The other script is actually a full fledged monitoring program that executes my script in an interval of 10-15 minutes. I set `Visible` property to `$true` to see whether or not web page correctly loads, it loads fine and I can see the button, but when my script tries to get the element, it gets a null object. – user6037143 Nov 28 '18 at 15:27
  • If you provide any sample script and detailed steps then we can try to make a test with it to find the issue. With only description, It is hard for us to accurately comment about any specific issue. Thanks for your understanding. – Deepak-MSFT Nov 29 '18 at 03:27

0 Answers0