Powershell 方法调用失败,因为[System.ComObject]不包含名为“IHTMLDocument3\u getElementsByTagName”的方法

Powershell 方法调用失败,因为[System.ComObject]不包含名为“IHTMLDocument3\u getElementsByTagName”的方法,powershell,invalidoperationexception,method-invocation,methodnotfound,Powershell,Invalidoperationexception,Method Invocation,Methodnotfound,我遇到了一个即使在疯狂的谷歌搜索后也无法解决的问题。我的PowerShell脚本打开网站,输入登录凭据,然后在网站上选择可单击的链接。这是我遇到麻烦的可点击链接 以下行在我的PC Windows 10上工作,但在我的服务器2012上失败: $Link=$ie.Document.IHTMLDocument3_getElementsByTagName("a") | where-object {$_.innerText -eq "Go to app"} 错误是: Method invocation

我遇到了一个即使在疯狂的谷歌搜索后也无法解决的问题。我的PowerShell脚本打开网站,输入登录凭据,然后在网站上选择可单击的链接。这是我遇到麻烦的可点击链接

以下行在我的PC Windows 10上工作,但在我的服务器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

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

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

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

选中对象上的“获取成员”。它可能会被命名为与HTML2不同的名称,因为它是不同的操作系统版本| gm我能看到的最近的一个是'GetElementType',但它出现在两台没有IHTMLDocument3的实际$ie.Document对象上。我在两台计算机上都有此错误:HRESULT:0x800A01B6在D:\script.ps1:54 char:1+$Link=$ie.Document.getElementsByTagNamea | where object{$\内部…++CategoryInfo:OperationsStopped:[],NotSupportedException+FullyQualifiedErrorId:System.NotSupportedException不能对空值表达式调用方法。在D:\script.ps1:55处char:1+$link.click+~~~~~~~~~+CategoryInfo:InvalidOperation:[],RuntimeException+FullyQualifiedErrorId:InvokeMethodUnll