Ich habe ein HTML-Formular so zu automatisieren, Surfen im Internet:versuchen
<input name="member[email]" id="memberemail" style="width: 220px;" type="text" value="">
<input name="member[password]" id="memberpassword" style="width: 220px;" type="password" value="" autocomplete="off">
<input class="continue" type="submit" value="Log In">
und ich habe einen Powershell-Skript, das authentifiziert und blättert eine Seite: das funktioniert gut.
$username='[email protected]'
$password='<password>'
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true
$ie.Navigate("https://www.ksl.com/public/member/signin?login_forward=%2F")
while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}
$usernamefield = $ie.Document.getElementByID('memberemail')
$usernamefield.value = $username
$passwordfield = $ie.Document.getElementByID('memberpassword')
$passwordfield.value = $password
$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.className -eq "continue"}
#<INPUT tabIndex=3 id=Logon onclick=this.disabled=true;this.form.submit(); type=submit value="Sign In">
#<input name="ctl00$pageContentPlaceHolder$btnGo" id="ctl00_pageContentPlaceHolder_btnGo" style="width: 200px;" type="submit" value="Sign In">
$Link.click()
aber wenn ich versuche, und es auf einer ASP.net Seite wie diese verwenden:
<input name="ctl00$pageContentPlaceHolder$txtUserID" id="ctl00_pageContentPlaceHolder_txtUserID" style="width: 200px;" type="text" maxlength="30" autocomplete="off">
<input name="ctl00$pageContentPlaceHolder$txtPassword" id="ctl00_pageContentPlaceHolder_txtPassword" style="width: 200px;" type="password" maxlength="256" autocomplete="off">
<input name="ctl00$pageContentPlaceHolder$btnGo" id="ctl00_pageContentPlaceHolder_btnGo" style="width: 200px;" type="submit" value="Sign In">
dieses modiified Skript füllt nicht den Benutzernamen und das Passwort-Feld
$username='use000'
$password='<password>'
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true
#ie.Navigate("https://fasttrng.usask.ca/Login.aspx?ReturnUrl=%2f")
while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}
$usernamefield = $ie.Document.getElementByName('ctl00$pageContentPlaceHolder$txtUserID')
$usernamefield.value = $username
$passwordfield = $ie.Document.getElementByName('ctl00$pageContentPlaceHolder$txtPassword')
$passwordfield.value = $password
$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.id -eq "ctl00_pageContentPlaceHolder_btnGo"}
$Link.click()
I erhalten
PS C:\Users\rwm132> T:\work\scripts\Untitled4.ps1
PS C:\Users\rwm132> T:\work\scripts\Untitled4.ps1
PS C:\Users\rwm132> T:\work\scripts\Untitled5.ps1
You cannot call a method on a null-valued expression.
At T:\work\scripts\Untitled5.ps1:11 char:1
+ $usernamefield = $ie.Document.getElementByName('ctl00$pageContentPlac ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At T:\work\scripts\Untitled5.ps1:12 char:1
+ $usernamefield.value = $username
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
You cannot call a method on a null-valued expression.
At T:\work\scripts\Untitled5.ps1:14 char:1
+ $passwordfield = $ie.Document.getElementByName('ctl00$pageContentPlac ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At T:\work\scripts\Untitled5.ps1:15 char:1
+ $passwordfield.value = $password
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
You cannot call a method on a null-valued expression.
At T:\work\scripts\Untitled5.ps1:17 char:1
+ $Link=$ie.Document.getElementsByTagName("input") | where-object {$_.i ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At T:\work\scripts\Untitled5.ps1:22 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
PS C:\Users\rwm132>
Ist da etwas Besonderes über die ASP.Net gerenderten Eingabefelder?
Nur eine Vermutung, aber müssen Sie die Zeichen "$" zu entkommen? Oder warum hast du sogar von "getElementByID" auf "getElementByName" gewechselt? –
Ja, ich hatte ursprünglich ByID, aber das hat auch nicht funktioniert ... das ist eine .NET-Seite jemand schlug vor, dass diese Methode nicht mit AJAX funktioniert. nicht sicher, ob sut, weil Sie sehen, Name = "ctl00 $ pageContentPlaceHolder $ txtUserID" ID = "ctl00_pageContentPlaceHolder_txtUserID" zeigt an, dass es sich um eine AJAX-Seite, die ich war das reine Server-Seite ASP.NET? Was denkst du, JamesZ –
Ich denke immer noch über die Flucht $, nicht sicher, ob es das Problem ist, aber kann nicht herausfinden, was sonst so schlimm falsch gehen könnte –