javascript in powershell

This topic contains 3 replies, has 2 voices, and was last updated by  Tony Antony 3 weeks, 5 days ago.

  • Author
    Posts
  • #80170

    Tony Antony
    Participant

    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

  • #80201

    Snak3d0c
    Participant

    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()
    
    
  • #80242

    Tony Antony
    Participant

    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

  • #80243

    Tony Antony
    Participant

You must be logged in to reply to this topic.