I am trying to use WWW::Mechanize to automate navigation of a webpage that requires me to click on at least one button that is tied to javascript code. I know that WWW::Mechanize does not support javascript but am trying to avoid using WWW::Mechanize::Firefox because I don't want to deal with the GUI.

Given that, I am trying to decipher the data that is transmitted when I navigate through the website using a browser to see if I can just manually do what the javascript is doing within my perl code.

When I click the button manually, here is the POST data:



cbd_ria:true ANSWER:******* LoginForm:ANSWER:******* LoginForm:DEVICE:true ANTI_CSRF_TOKEN:9ec2f31c-4008-4bce-b759-3b3aceda6f42 LoginForm:LoginForm


Here is the response header:



Content-language:en-US Content-length:0 Date:Fri, 04 Jul 2014 04:12:25 GMT Location:https://****************************** P3p:CP='NOI CURa ADMa DEVa TAIa OUR BUS IND UNI COM NAV INT' Set-cookie:PMData=PMV6GDrDYODTPUcMqubLWUJOi%2BhcTJGSUaC%2B%2Fk0FN2ITW8 +Isa1Awx90hD%2B3wCtpjInRT5Gw%2Bye28N9Tr6uhoe8T9R30g%3D%3D;path=/;HttpO +nly; Expires=Sat, 04 Jul 2015 04:12:24 GMT; Domain=**********.com; Se +cure X-frame-options:SAMEORIGIN


When I manually fill out the boxes corresponding to LoginForm:ANSWER and LoginForm:DEVICE and then click the continue button, the website authenticates my responses and then takes me to the location specified in the "Location:" field of the response header, which is where I intend to go.

How would I replicate what the javascript is doing within perl? Do I just fill out all the fields in the POST data above, and then GET the Location: URL?

Filling out the LoginForm:ANSWER and LoginForm:DEVICE fields is easy enough, but what about the ANTI_CSRF_TOKEN? I have no idea how to generate it. Is it even required?

Also I did some searching and stumbled on a few perl javascript engines such as JavaScript::SpiderMonkey, WWW-Scripter-Plugin-JavaScript, and WWW-Mechanize-PhantomJS. All of these have an eval() function. The button I am trying to press has the following code tied to it:



<input type="button" value="Continue" tabindex="1" onkeypress="fd.butt +on._keyPress(event, 'LoginForm:continue')" initialtabindex="1" class= +"btn" id="LoginForm:continueInput">


In this case, the button appears to take the following action:



fd.button._keyPress(event, 'LoginForm:continue')


If I use one of the javascript modules, is it literally as simple as calling eval on the function bound to the button once I have set the appropriate variables (I assume the JS function will handle the ANTI_CSRF_TOKEN?)


In reply to WWW::Mechanize and buttons tied to javascript by Special_K

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.