方法调用失败,因为[System.ComObject]不包含名为“IHTMLDocument3_getElementsByTagName”的方法

问题描述 投票:0回答:1

我遇到了一个问题,即使经过一些疯狂的谷歌搜索后我也无法弄明白。我的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

这使我的'click'命令失败:

$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。任何想法或建议非常感谢!即使是改变我完全选择可点击链接的方式:)

powershell invalidoperationexception method-invocation methodnotfound
1个回答
0
投票

以下工作在我的Windows 10工作站和Windows Server 2012上都有效

$Link=$ie.Document.getElementsByTagName("a") |  where-object {$_.innerText -eq "Go to app"}
© www.soinside.com 2019 - 2024. All rights reserved.