http://www.perlmonks.org?node_id=966180

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

Hi Monks,

I have a problem to login a wbsite which calls javascript, I read docs where they suggested to use WWW::Scripter. But no luck. Look into my code and source of website. and suggest me the best way to resolve this issue.
my $mech = WWW::Scripter->new(); $mech->agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.2.3) + Gecko/201 00401'); $mech->use_plugin(JavaScript => engine => 'JE', ); $mech->get("https://www.mywesite.com/plp/login.do"); print $mech->content; $mech->submit_form( with_fields => { userId => 'myId', pass => 'myPass +' } );
Here my submit button calls a Jscript function called submitLoginForm; Submit :
--<td class="submitButton" id="SignInButton"> <a href="#" onclick='return submit +LoginForm("ACTION_PIN_LOGIN","myLogin");'>
Here the function details
function submitLoginForm(val,source) { if(val == "ACTION_PIN_LOGIN") removeSignInButton(); document.forms['LoginForm'].action.value = val; document.forms['LoginForm'].source.value = source; document.forms['LoginForm'].submit(); return false; }
help me to resolve this issue

Thanks in Advance

Replies are listed 'Best First'.
Re: Login Website
by thomas895 (Deacon) on Apr 20, 2012 at 13:24 UTC

    And this is why I hate letting everyone use HTML as they please on here.
    OP: You're going to have to escape that HTML or find another way to show it to us(e.g., a pastebin).

    Update(20apr2012):

    Now that I can read this properly(thanks guys), I might be able to help you. But first you will have to tell us: what was the expected result? What actually happened? What other things have you tried, and what was their result?

    ~Thomas~
      Not able to login, it displays the home page content only when I print mech-content. I want to login and print the target content.
Re: Login Website
by Riales (Hermit) on Apr 20, 2012 at 17:36 UTC
    You could try triggering the site's own submitLoginForm function with trigger_event:
    # This won't work exactly, but it's a hint: $w->document->links->[0]->trigger_event('onclick');
      No luck, can anybody suggest

        Well, are you married to the idea of using WWW::Scripter? I've had a great deal of success using WWW::Selenium for automating javascript-heavy web pages. Might be worth looking into?