I've run into a problem that I can't figure out even after some frantic Googling. My PowerShell Script opens up a website, enters log in credentials and then selects a clickable link on the site. It is the clickable link I am having trouble with.

The following line works on my PC (Windows 10) but fails on my server (Server 2012):

$Link=$ie.Document.IHTMLDocument3_getElementsByTagName("a") | where-object {$_.innerText -eq "Go to app"}

The error is:

Method invocation failed because [System.ComObject] does not contain a method named 
'IHTMLDocument3_getElementsByTagName'.
At C:\script.ps1:53 char:1
$Link=$ie.Document.IHTMLDocument3_getElementsByTagName("a") | where-object {$_.i ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (IHTMLDocument3_getElementsByTagName:String) [], RunTimeException
    + FullyQualifiedErrorID : MethodNotFound

This then makes my 'click' command fail:

$link.click()

Fails with:

You cannot call a method on a null-valued expression.
At C:\script.ps1:54 char:1
+link.click()
+~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RunTimeException
    + FullyQualifiedErrorID : InvokeMethodOnNull

I've ensured that .NET 4.5 is installed on the server. Any ideas or suggestions greatly appreciated! Even if it is to change the way I select the clickable link altogether :)

1

There are 1 answers

1
Guenther Schmitz On

the following works both on my Windows 10 workstation as well as on a Windows Server 2012

$Link=$ie.Document.getElementsByTagName("a") |  where-object {$_.innerText -eq "Go to app"}