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

时间:2018-05-14 15:01:06

标签: powershell invalidoperationexception method-invocation methodnotfound

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

以下行可在我的电脑上运行(Windows 10)但在我的服务器上失败(Server 2012):

Caused by java.lang.SecurityException: Caller no longer running, last stopped +206ms because: timed out while starting
   at android.os.Parcel.readException(Parcel.java:1942)
   at android.os.Parcel.readException(Parcel.java:1888)
   at android.app.job.IJobCallback$Stub$Proxy.dequeueWork(IJobCallback.java:191)
   at android.app.job.JobParameters.dequeueWork(JobParameters.java:196)
   at android.support.v4.app.JobIntentService$JobServiceEngineImpl.dequeueWork(JobIntentService.java:314)
   at android.support.v4.app.JobIntentService.dequeueWork(JobIntentService.java:639)
   at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:389)
   at android.support.v4.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:382)
   at android.os.AsyncTask$2.call(AsyncTask.java:333)
   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
   at java.lang.Thread.run(Thread.java:764)

错误是:

$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()

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

1 个答案:

答案 0 :(得分:0)

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

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