简体   繁体   English

Powershell-单击HTML代码上的提交按钮

[英]Powershell - click submit button on HTML code

I tried many different ways to click submit button on HTML code, but always got error. 我尝试了许多不同的方法来单击HTML代码上的Submit按钮,但始终会出错。

<form action="abnormal-times.aspx" method="post">
Time out Minutes <input name="Minutes" style="width: 100px;" value="5"> Minutes.<br>
Time out Hours <input name="Minutes" style="width: 100px;" value="2"> Hours.
<input onclick="submit()" type="button" value="submit">

With my powershell code: 用我的PowerShell代码:

$ie = New-Object -com InternetExplorer.Application 
$ie.visible = $true
$ie.navigate("http://localhost.com")

while($ie.ReadyState -ne 4) { start-sleep -s 1 }

$Link = $ie.Document.getElementsByValue("submit")
$Link.click()

But always popup error. 但是总是弹出错误。

Method invocation failed because [mshtml.HTMLDocumentClass] doesn't contain a method
 named 'getElementsByValue'.
At C:\temp\Untitled1.ps1:28 char:42
+ $Link = $ie.Document.getElementsByValue <<<< ("submit")
    + CategoryInfo          : InvalidOperation: (getElementsByValue:String) [], Run 
   timeException
    + FullyQualifiedErrorId : MethodNotFound

You cannot call a method on a null-valued expression.
At C:\temp\Untitled1.ps1:29 char:14
+ $Link.click <<<< ()
    + CategoryInfo          : InvalidOperation: (click:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Now I changed into this: 现在我变成了:

$Link=$ie.Document.getElementsByTagName("button") | where-object {$_.type -eq "submit"}
$Link.click()

The error came out: 错误出来了:

You cannot call a method on a null-valued expression.
At C:\Users\Work_Server\Desktop\joseph.ps1:29 char:10
+ $go.click <<<< ()
    + CategoryInfo          : InvalidOperation: (click:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The tag name of your button is input , and the type is button . input按钮的标签名称类型button Try this. 尝试这个。

$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.type -eq "button"}
$Link.click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM