我正在查看输入类型为“提交”的网页:
<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">
我想使用PowerShell“点击”此输入。我的脚本看起来像:
$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
我正在使用StackOverflow上另一个用户的代码,我假设他正在与按钮输入进行交互。但这是一个“提交”。我已经尝试了here发布的解决方案,但得到错误:
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
和
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
分别
如何点击此按钮?