1

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
1
  • 4
    The object doesn't have a method getElementsByValue, so you can't call it. You can verify that by running $ie.Document | Get-Member. Use $ie.Document.getElementsByName or $ie.Document.getElementsByTagName instead and filter the results with Where-Object. Commented Mar 11, 2014 at 12:03

1 Answer 1

7

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.