Author Posts

September 19, 2017 at 8:36 pm

Hello,

We have IP cameras at work with user accounts. I'm trying to automate the login process. I figured out how to input username and password from PowerShell, but I'm not sure how to login.

So, the username is "Cam1", and the password is "P@$$word". But when I type in $web.Forms, it doesn't show any forms, so I don't now what to do.

I noticed it have a login(), but how would I do that?

outerText :  
tagName   : DIV
class     : login-item

innerHTML : 
innerText : 
outerHTML : 
outerText : 
tagName   : BUTTON
class     : btn btn-primary login-btn
type      : button
ng-click  : login()
PS C:\WINDOWS\system32> $web.InputFields


innerHTML    : 
innerText    : 
outerHTML    : 
outerText    : 
tagName      : INPUT
class        : login-input
id           : username
type         : text
maxlength    : 32
placeholder  : Cam1
autocomplete : off
ng-model     : username

innerHTML   : 
innerText   : 
outerHTML   : 
outerText   : 
tagName     : INPUT
class       : login-input
id          : password
type        : password
maxlength   : 16
placeholder : P@$$word
ng-model    : password

Thanks,

Tony

September 20, 2017 at 8:46 am

You would have to access the DOM-object.
So catch the button you are looking for and then invoke a Click() action.

So simply put, if there is only one button on that page, it would look something like:


    $MyButton = $ie.Document.getElementsByTagName("button")| where-object {$_.type -eq "submit"} 
    $MyButton.click()

September 20, 2017 at 2:05 pm

Thank you for the DOM-Object idea, but unfortunately, I'm still getting error saying it can't find the "button"

This is my code so far

$browser=new-object -com internetexplorer.application

$cam1url = Invoke-WebRequest -Uri "http://10.2.1.221/doc/page/login.asp?_1505848323057/login.asp" -SessionVariable session
$cam1url.InputFields.FindById("username").placeholder = "Shredder"
$cam1url.InputFields.FindById("password").placeholder = "UIMShred*"

$cam1 = Invoke-WebRequest -Uri "http://10.2.1.221/doc/page/preview.asp" -WebSession $session

$loginButton = $browser.Document.getElementsByTagName("button")| where-object {$_.type -eq "type"}
$loginButton.click()

$browser.navigate2("http://10.2.1.221/doc/page/preview.asp")
$browser.visible=$true

This is the error message:

You cannot call a method on a null-valued expression.
At \\arg-fs2\users\tantony\towerCameras.ps1:9 char:1
+ $loginButton = $browser.Document.getElementsByTagName("button")| wher ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At \\arg-fs2\users\tantony\towerCameras.ps1:10 char:1
+ $loginButton.click()
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

And, this is the HTML portion