trying to automate browsing

0

I have an HTML Form like this:

<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">

and I have a powershell script that authenticates and browses a page: this works fine.

$username='xxx@mail.com' 
$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()

however when I try and use it on a ASP.net page like this:

<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">

this modiified script doesn't fill the username and password field

$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 get

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> 

Is there something special about the ASP.Net rendered inputs fields?

powershell
internet-explorer
ui-automation
asked on Stack Overflow Aug 7, 2017 by R.Merritt • edited Aug 7, 2017 by R.Merritt

1 Answer

0

the script works for static html just not ASP.Net someone suggested that it cannot handle the AJAX part that is being presented , does that sound right? I thought webforms like this in .NET were e

answered on Stack Overflow Aug 10, 2017 by RobM

User contributions licensed under CC BY-SA 3.0