locked
PowerShell to invoke HTML click() - onclick="Javascript:window.open RRS feed

  • Question

  • Hi,

    I'm using IE 9 to  access     http://iamresponding.com      and am trying to use PowerShell to click the "Subscriber Login" button in the upper right corner of the page.  This is the code snippet from the View Source that I'm trying to access:

    <body>
      <div id="MainContainer">
        <form name="aspnetForm" method="post" action="Default.aspx" id="aspnetForm">
          <div>
            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTQ5NjkzMDU3OGRkno5l7teYCI8QpQLNif9+SDrTICA=" />
          </div>
          <div id="MainHeader">           
            <div class="header-container">
              <img alt="Emergency Responder Reply System" src="../images1/IAR_logo2_medium.png" />
              <a onclick="Javascript:window.open('../memberlogin.aspx','MenuPopup','Scrollbars=no,menubars=no,toolbars=no,width=459,height=279');" href="#">Subscriber Login</a>
            </div>
          </div>

    I am using PowerShell ISE and have a try/catch block where I am using PowerShell Write-Output command to help figure out how to acccess the button so I can invoke the click() method in the Document Object Model.

    Any help would be greatly appreciated.

    Thanks, Mike

     

    Saturday, January 28, 2012 4:45 AM

Answers

  • Thanks to all for the replies.

    I am disapointed that this is not able to be done using IE without an addin or hook or by using the COM object alone.

    • Marked as answer by MRowe31 Saturday, January 28, 2012 3:37 PM
    Saturday, January 28, 2012 3:37 PM

All replies

  • Hi,

    I'm using IE 9 to  access     http://iamresponding.com      and am trying to use PowerShell to click the "Subscriber Login" button in the upper right corner of the page.  This is the code snippet from the View Source that I'm trying to access:

    <body>
      <div id="MainContainer">
        <form name="aspnetForm" method="post" action="Default.aspx" id="aspnetForm">
          <div>
            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTQ5NjkzMDU3OGRkno5l7teYCI8QpQLNif9+SDrTICA=" />
          </div>
          <div id="MainHeader">           
            <div class="header-container">
              <img alt="Emergency Responder Reply System" src="../images1/IAR_logo2_medium.png" />
              <a onclick="Javascript:window.open('../memberlogin.aspx','MenuPopup','Scrollbars=no,menubars=no,toolbars=no,width=459,height=279');" href="#">Subscriber Login</a>
            </div>
          </div>

    I am using PowerShell ISE and have a try/catch block where I am using PowerShell Write-Output command to help figure out how to acccess the button so I can invoke the click() method in the Document Object Model.

    Any help would be greatly appreciated.

    Thanks, Mike

     


    Cannot be done.

    Security settings do not allow you to send events to a page from an external script.

    If this could be done every hacker in Eastern Europe and China would have an easy job.  In fact hackers would beput out of business by elementary school kiddies clicking their way though the internet with their script-kiddie goodies.

    Events can only originate from withing the sandboxed IE session and not from an extrnal program.

     


    jv
    Saturday, January 28, 2012 5:54 AM
  • Of course this can be done!

    I have looked into the Page source. and the login button simly redirects to a Link!
    Why you simply not use the Link?
    http://iamresponding.com/v3/memberlogin.aspx !!!!!

     

    Obtain a IE COM Object and Automate it !
    But this is hard because you dont have a strong binding, you are running into time sync problems!

    Automate a Javascrpt Button:
    stions/1444330/execute-javascript-trough-internet-explorers-com-interface-using-powershell

    See here the Submit Button action:
    http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467

    ######## Snip ###########
    # Click the submit button $ie.Document.getElementById("signin_submit").Click();
    ######## Snip ###########
    
    


    You can also use the PowerShell WASP Module:
    http://stackoverflow.com/questions/8173867/automating-ie-confirmation-prompt-with-powershell
     


    Please click “Mark as Answer” on the post that helps you. Thank you ;-)) Bitte markiere hilfreiche Beiträge von mir als "Hilfreich" und Beiträge die deine Frage ganz oder teilweise beantwortet haben als "Antwort". Das wäre Nett :-))


    Saturday, January 28, 2012 8:01 AM
  • Sorry but uit is not possible to use automation to send events to a page.  If you guild the page entrely from scratch using automation you can cause an event.  Pages loaded from the internet are protected.

     

     


    jv
    Saturday, January 28, 2012 9:18 AM
  • I have a Password Storage application, and one can from this application, invoke IE.  Then a hot-key will fill in the login fields that I have defined, and "Press Enter" for me.

    How is this possible if IE is not accessible from outside?


    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Network Live Audit - Powershell script
    Saturday, January 28, 2012 9:27 AM
  • You have at leat three way...

     using the internet explorer com objet and simulating the navigation
    http://msdn.microsoft.com/en-us/magazine/cc337896.aspx

    making the form post using  net.WebClient
    http://msdn.microsoft.com/en-us/magazine/cc507642.aspx

    or using an helper application/library like curl
    http://curl.haxx.se/
    http://curl.haxx.se/libcurl/dotnet/

     

    Using curl is my preferred an more easy then the other


    Gastone Canali >http://www.armadillo.it
    Saturday, January 28, 2012 10:32 AM
  • Windows Powershell V3 includes command like wget/curl
    http://rambletech.wordpress.com/2011/09/21/windows-powershell-v3-includes-command-like-wgetcurl/

    Simulate Curl / Wget in Powershell with .NET Classes
    http://matthewbadeau.com/blog/?p=18


    Please click “Mark as Answer” on the post that helps you. Thank you ;-)) Bitte markiere hilfreiche Beiträge von mir als "Hilfreich" und Beiträge die deine Frage ganz oder teilweise beantwortet haben als "Antwort". Das wäre Nett :-))
    Saturday, January 28, 2012 11:37 AM
  • Thank you all for the replies.

    If it were simply a matter of using the url   http://iamresponding.com/v3/memberlogin.aspx   I wouldn't be having this problem. Invoking this url simply brings up this same page and doesn't solve my problem.

    How do I access the "Subscriber Login" button that will respond to the click() event? If you look at the original code fragment or view the page source, you see that there is no button defined. Instead, there is the tag

    <div class="header-container">
    that contains 
    <a onclick="Javascript:window.open('../memberlogin.aspx','MenuPopup','Scrollbars=no,menubars=no,toolbars=no,width=459,height=279');" href="#">Subscriber Login</a>
    How do I use DOM to invoke the click() method?  Once the child login form is opened as a result of the click() event, I can then enter the authentication information.  How do I bring up that form?

    Again, thanks

    Mike

     

    Saturday, January 28, 2012 2:31 PM
  • I have a Password Storage application, and one can from this application, invoke IE.  Then a hot-key will fill in the login fields that I have defined, and "Press Enter" for me.

    How is this possible if IE is not accessible from outside?


    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Network Live Audit - Powershell script


    Yes - it installs a hook into IE.  This is the only way to do this.  We can use a compiled object to hook teh IE WIndow.  In some cases you an use SendKeys to do a similar thing.

    This is why keystroke loggers are very dangerous.

     

     


    jv
    Saturday, January 28, 2012 3:15 PM
  • Thank you all for the replies.

    If it were simply a matter of using the url   http://iamresponding.com/v3/memberlogin.aspx   I wouldn't be having this problem. Invoking this url simply brings up this same page and doesn't solve my problem.

    How do I access the "Subscriber Login" button that will respond to the click() event? If you look at the original code fragment or view the page source, you see that there is no button defined. Instead, there is the tag

    <div class="header-container">
    that contains 
    <a onclick="Javascript:window.open('../memberlogin.aspx','MenuPopup','Scrollbars=no,menubars=no,toolbars=no,width=459,height=279');" href="#">Subscriber Login</a>
    How do I use DOM to invoke the click() method?  Once the child login form is opened as a result of the click() event, I can then enter the authentication information.  How do I bring up that form?

     

    Again, thanks

    Mike

     


    Again - the answer is you can't.  YOu need to use an addin or directly use teh WebClient if the login page allows this.  Mosy login pages have been designed to prevent 'bots' from accessing the login form.

    If this were a normal HRML 'From' page that uses a submit it can be logged into ising the WebCLient.  Yuo cannot automate IE to do this without an add-in or 'hook' code.

     


    jv
    Saturday, January 28, 2012 3:18 PM
  • Thanks to all for the replies.

    I am disapointed that this is not able to be done using IE without an addin or hook or by using the COM object alone.

    • Marked as answer by MRowe31 Saturday, January 28, 2012 3:37 PM
    Saturday, January 28, 2012 3:37 PM
  • Thanks to all for the replies.

    I am disapointed that this is not able to be done using IE without an addin or hook or by using the COM object alone.


    Thereis not modern browser that allow this to be done.  We used to be able to doit in IE5 I believe but, for security reasons, IE has been locked down. 

    Just think of the bad things that could happen if any script running in the system could reach out to a secure web page.  Even in an infected system your web pages are mostly secure except for infection by keystroke loggers although they may not be able tp read the pages content even if they can capture your keystrokes.

    Even SendKeys fails when using secure web forms because it cannot know where the data entry is and the secure form is not addresable via COM.

    The examples of how to execute javascript in a web page all create teh page content from code.  Now you can call this 'click' event of your hand built form and it will work.  It just cannot be tied to a web site. 

    This is useful for creqating reports and animating them. It is not useful on websites.

    What you are asking to do would be called a 'code injection attack'

     


    jv
    Saturday, January 28, 2012 3:49 PM
  • Thanks to all for the replies.

    I am disapointed that this is not able to be done using IE without an addin or hook or by using the COM object alone.


    Maybe so, but if this were possible, as jrv said, it would be a huge security risk.
    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Network Live Audit - Powershell script
    Saturday, January 28, 2012 4:29 PM
  • Hi

    I have two places where my input trigger should go

    a) Text-field

    b) Submit button

    for both i referred to aboveve post of - Peter Kriegel

    $spans=@($ie.document.getElementsByTagName("SPAN"))

    Pipe to where-object to filter the one you need (based on its attributes) and then call the click method, for example:

    $span11 = $spans | where {$_.innerText -eq 'something'} # for text-field

    $span12 = $spans | where {$_.value -eq 'something'}  # for text field

    $span11.click();
    $span12.click();

    and it worked for me (which change in $_.innerText & $_.value)

    I can see my text is entered into Text-field and even i can observe the Submit button got hit... but unfortunately.. the page is not getting submitted (for submitting some redirection should happen... but in my case it doent happen)

    Is this the security issue? or I am making some mistake?



    • Edited by Fackeid_Test Sunday, February 26, 2012 10:59 PM Typo
    Sunday, February 26, 2012 10:58 PM
  • Hi

    I have two places where my input trigger should go

    a) Text-field

    b) Submit button

    for both i referred to aboveve post of - Peter Kriegel

    $spans=@($ie.document.getElementsByTagName("SPAN"))

    Pipe to where-object to filter the one you need (based on its attributes) and then call the click method, for example:

    $span11 = $spans | where {$_.innerText -eq 'something'} # for text-field

    $span12 = $spans | where {$_.value -eq 'something'}  # for text field

    $span11.click();
    $span12.click();

    and it worked for me (which change in $_.innerText & $_.value)

    I can see my text is entered into Text-field and even i can observe the Submit button got hit... but unfortunately.. the page is not getting submitted (for submitting some redirection should happen... but in my case it doent happen)

    Is this the security issue? or I am making some mistake?



    As I have posted dozens of times.  You cannot change a page then post it.  The change are local only and the page will not submit because you have altered it.

    You can dummy up a for with the web client but it may not work as many pages are not really being submitted by HTTP but are being submitted via JavaScript or other mechanism.

    This topic was closed over a month ago.  It you have more questions I recommend that you start a new topic.


    ¯\_(ツ)_/¯

    Sunday, February 26, 2012 11:16 PM