0

我遇到了一个问题,即使经过一些疯狂的谷歌搜索,我也无法弄清楚。我的 PowerShell 脚本会打开一个网站,输入登录凭据,然后在该网站上选择一个可点击的链接。这是我遇到问题的可点击链接。

以下行在我的 PC (Windows 10) 上有效,但在我的服务器 (Server 2012) 上失败:

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

错误是:

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

然后这使我的“点击”命令失败:

$link.click()

失败:

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

我已确保在服务器上安装了 .NET 4.5。任何想法或建议都非常感谢!即使是要改变我完全选择可点击链接的方式:)

4

1 回答 1

0

以下适用于我的 Windows 10 工作站以及 Windows Server 2012

$Link=$ie.Document.getElementsByTagName("a") |  where-object {$_.innerText -eq "Go to app"}
于 2018-05-15T16:08:43.787 回答