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

I know WWW::Mechanize doesn't support javscript but I'm trying to do a simple POST but the response page gives a javscript warning:
You cannot use the website without having JavaScript enabled on your w +eb browser. Please re-enable JavaScript and refresh this page.
Is there a way to trick the page into thinking I have javascript enabled via the mech constructor? I was thinking maybe I need to modify the headers before making the POST for instance:
$mech->add_header( 'Accept' => 'application/json, text/javascript, */* +' );

Any thoughts?

Replies are listed 'Best First'.
Re: Enabling javascript in Mechanize?
by Corion (Patriarch) on Sep 08, 2010 at 13:26 UTC

    Have you tried using the website with Javascript disabled in your browser? Have you looked at the difference in headers that your browser sends as opposed to what WWW::Mechanize sends? Have you looked at the web page source that is used to determine whether you have Javascript enabled or not?

    Also, see the documentation of WWW::Mechanize, which tells you that there is no hidden magic by which you can "enable" Javascript in WWW::Mechanize.

    There are Javascript-enabled alternatives to WWW::Mechanize, for example WWW::Scripter and WWW::Mechanize::Firefox.

Re: Enabling javascript in Mechanize?
by talexb (Chancellor) on Sep 08, 2010 at 14:21 UTC

    I'm starting to use Selenium along with Test::WWW::Selenium to test my web apps. It's a bit tricky, but it gets around the Javascript issue very neatly.

    And, in general, you should try to do as much manually as possible -- see what happens in a real browser, as another reply suggests. It could be that the web site will gracefully degrade if the client won't do Javascript.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds