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

Hi Monks,

I want to automate the interaction to a website by using Perl. The site only runs under IE/Windows, and it contains the following Javascript segment.

What I really want to do is present it with my own calculated (in Perl) xobj.reqFrm.frmSendMsg.detail.value and then trigger the SubmitMsg() routine programatically.

function SubmitMsg() { xobj.reqFrm.frmSendMsg.ac.value= xobj.GetDataStore("ac"); xobj.reqFrm.frmSendMsg.detail.value = xobj.CreateMsg(); xobj.reqFrm.frmSendMsg.signature.value = xobj.SignMsg( xobj.reqFrm.frmSendMsg.ac.value, xobj.reqFrm.frmSendMsg.detail.value); xobj.SubmitForm(xobj.reqFrm.frmSendMsg); }

How to do this sort of thing in Perl?

The signing process and other things in there that I removed for clarity. I would essentially like to leave most of it running under IE as there is just so much other .js code, llike the message signing and other routines.

Replies are listed 'Best First'.
Re: How to make Perl modify and trigger Javascript variable/function
by Anonymous Monk on Nov 26, 2009 at 07:13 UTC
      I'll taken a look, IEAutomation seems to be winning - found some interesting snippets. Still to figure out how to intercept the js variable setting. Thanks!

        If you can make the site work under FireFox, WWW::Mechanize::FireFox has the ->eval_in_page() method that allows you to run arbitrary Javascript in the context of a web page and transfer the result back to Perl. But it only works in FireFox, not in Internet Explorer.

Re: How to make Perl modify and trigger Javascript variable/function
by pemungkah (Priest) on Dec 03, 2009 at 22:18 UTC
    If you can drop a web proxy in there to record the data going across the wire when that Javascript fires, you can just do it in Perl and not use IE at all. That may give you more flexibility (and the ability to throw "bad" data at the backend to make sure it can handle it. Never trust the browser!).

      Thanks, emulating everything in Perl would be ideal but a rather big job I should imagine.

      I have managed to see a lot with Fiddler and ieHTTPHeaders, and a bit with Wireshark... but still I can't seem to find the where the SignMsg() hashing/digest function code is that creates the 172 character signature.

      If I know what algorithm it uses I could emulate it (I think)

      There's also an client certificate that is read in, and some aspx code.

      Ah ha - it seems there is an ActiveX controls for both signing and storing data - is it possibel to call those from within Perl?