我正试图通过PowerShell ISE登录网站。网页出现但它没有输入凭据。
$username = "DSmith"
$password = "Password123"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$false
$ie.navigate("https://feedback.camdenccg.nhs.uk/acl_users/credentials_cookie_auth/require_login? came_from=https%3A//feedback.camdenccg.nhs.uk/james-wigg-and-queens-crescent-practices/4ef32a4e/download_responses%3Foverride-query%3DTrue")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById('__ac_name').value= "$username"
$ie.document.getElementById('__ac_password').value = "$password"
$ie.document.getElementById("loginform").submit()
start-sleep 5
我得到的错误是:
The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))
At line:10 char:7
+ while($ie.ReadyState -ne 4) {start-sleep -m 100}
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
You cannot call a method on a null-valued expression.
At line:12 char:1
+ $ie.document.getElementById('__ac_name').value= "$username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
答案 0 :(得分:0)
查找标签名称以设置值,然后使用输入值进行单击。 (注意:还有其他方法可以实现这一点,我只是给你一个例子)
$username = "your user name"
$password = "your pass word"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
checkUrlStatusOk -endpoint $rabbitMQEndpoint
$ie.navigate("https://feedback.camdenccg.nhs.uk/acl_users/credentials_cookie_auth/require_login? came_from=https%3A//feedback.camdenccg.nhs.uk/james-wigg-and-queens-crescent-practices/4ef32a4e/download_responses%3Foverride-query%3DTrue")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$userField = $ie.document.getElementsByName("__ac_name")
@($userField)[0].value =$username
$passField = $ie.document.getElementsByName("__ac_password")
@($passField)[0].value =$password
#login submit
$loginButton = $ie.document.getElementsByTagName("input")
Foreach($element in $loginButton )
{
if($element.value -eq "Log In"){
Write-Host $element.click()
}
}
Start-Sleep 10