2015-01-07 10 views
0

powershell ISE를 통해 웹 사이트에 로그인하려고합니다. 웹 페이지가 나타나지만 자격 증명을 입력하지 않습니다.PowerShell을 통해 웹 사이트에 로그인

$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

올바른 ID는 __ac_name입니다. – Filburt

+0

네, 맞습니다. – Djbril

+0

'$ test = $ ie.document.getElementById ("loginform")' 'Get-Variable $ test'는 ID가 'loginform'인 페이지에 객체가 없음을 나타내는'null'을 반환합니다. 그래서 그것을 클릭 할 수 없습니다. 오브젝트 이름을 확인하고 대신 {getNameBeTagName' 또는 getElementsByType ("button") | {$ .Name -eq "loginform"}'을 사용하십시오. – meatspace

답변

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 
관련 문제