0

I'm looking at a webpage with an input of type "submit":

<input name="loginForm:j_idt56:loginButton" id="loginForm:j_idt56:loginButton" onclick="this.style.display='none'; document.getElementById('euLoginButDis').style.display='inline';" type="submit" value="Login">

I would like to use PowerShell to "click" this input. My script looks like:

$username = "USERNAME" 
$password = "PASSWORD"

$ie = New-Object -com InternetExplorer.Application 

$ie.visible=$true

$ie.navigate("URL") 

while($ie.ReadyState -ne 4) {start-sleep -m 100} 

$ie.document.getElementById("loginForm:j_idt21:username:username").value= "$username" 
$ie.document.getElementById("loginForm:j_idt42:password:passwordb").value = "$password" 
# $ie.document.getElementById("loginForm:j_idt56:loginButton").submit()

start-sleep 20 

# $ie.Document.body | Out-File -FilePath c:\web.txt 

I'm using code from another user on StackOverflow, who I assume was interacting with a button input. But this is a "submit". I've tried the solutions posted here, but get the errors:

You cannot call a method on a null-valued expression.
At line:16 char:36
+ $commit = $doc.getElementsByTagName <<<< ("input")
    + CategoryInfo          : InvalidOperation: (getElementsByTagName:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

and

You cannot call a method on a null-valued expression.
At line:16 char:36
+ $commit = $doc.getElementsByTagName <<<< ("input") | ? { $_.name -eq "commit" }
    + CategoryInfo          : InvalidOperation: (getElementsByTagName:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "click" with "0" argument(s): "The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))"
At line:17 char:29
+ if ($commit) { $commit.click <<<< () }
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodCOMException

respectively.

How can I click this button?

Gerald
  • 521
  • 1
  • 6
  • 16
  • Any reason you prefer powershell for automation over a webdriver-based tool? – orde Jun 23 '16 at 00:28
  • I am unfamiliar with webdriver-based tools. I had started thinking about doing this with AutoIt, but then realized I could do it with PowerShell. And since there are a lot of other potential uses for PowerShell in my work, I thought it would be a good learning exercise. What are the benefits of webdriver-based tools? – Gerald Jun 23 '16 at 12:10
  • Lots of benefits: OS-independent, open-source, multi-language support, vibrant user communities. The most popular one is selenium-webdriver, so you might want to check that out. – orde Jun 23 '16 at 16:24

0 Answers0