I tried many different ways to click submit button on HTML code, but always got error.
<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:
$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
. Try this.
$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.type -eq "button"}
$Link.click();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.