ShipMyPants has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I'm just getting started with PERL trying to use it to automate entering inventory requests on a web page at work. I've found and been fairly successful with WWW::Mechanize.

I've got everything working except the submit action of the automation. When looking at the HTML source , I see that the "onclick" attribute references a javascript function that simply validates some entries on the page and returns "true" or "false".

I understand (sorta) that I could either invoke an external javascript engine like spidermonkey or somehow provide the proper "true" response programmatically to make it "appear" the javascript ran and the form gets submitted. My understanding of how HTML forms are submitted and the overall interaction between the browser and the server is elementary at best.

Could someone help me understand if I'm thinking about this correctly and if there is a straightforward way for me to bypass the actual "click" of the button and submit the form directly via Perl/Mechanize?

Thanks in advance : ShipMyPants

Replies are listed 'Best First'.
Re: Mechanize Javascript workaround?
by Corion (Patriarch) on Jul 19, 2013 at 21:24 UTC

    I usually use the Mozilla HTTP Live Headers extension to find what values actually go over the wire and then replicate that using WWW::Mechanize.

    If that becomes too tedious and you have Firefox available, you could use WWW::Mechanize::Firefox, which automates Firefox to implement Javascript with a WWW::Mechanize compatible API.

Re: Mechanize Javascript workaround?
by thomas895 (Deacon) on Jul 19, 2013 at 23:03 UTC

    If it only validates, you might not need to implement it at all, per se. Just ensure that your data is correct before submitting the form.

    ~Thomas~ 
    "Excuse me for butting in, but I'm interrupt-driven..."

      Monks,

      Thanks for the information.

      I've made a lot of progress.

      Question I have is when using the submit_form , do I need to manually collect the form contents and include it in the submit_form function call? Or does the submit_form function collect the current form and include it automatically?

      Also , I see that the submit button I'm trying to bypass references a specific requestsubmit.php file on the server. I'm guessing I need to include that detail in the submit_form call but I don't see a way to do it.

      Thanks again for all the great insight. I'm learning alot and really appreciate your help.

      -ShipMyPants