views:

150

answers:

3

Hello,

I understand a few people have asked about JS support in Mechanize. My question might be a little bit different, and/or posed differently. I am looking to ignore the Javascript check and log in to a page that requires Javascript. The web site itself does not really need JS, but the developers felt they needed to require it for the best appearance.

With that said, has anyone been able to circumvent the check for JS? I could use Watir, Watij, Selenium, or a surplus of other utilities but they open an actual browser which was not that desirable -- but if this is the only way I guess I'll go that route.

I'm running Mac OS X, Ruby 1.8.7, Mechanize/Hpricot (latest as of this post). Thanks.

A: 

Generally speaking, the simplest option is to work out what the server expects the user-agent to send to claim that it supports JS (either by monitoring the HTTP requests (perhaps with Charles Proxy) sent by a browser with JS enabled or by reverse engineering the JS) and then just having your script send that information.

David Dorward
Here is the JS on the page I am attempting to access:<script language="JavaScript">function newscreen(){ window.open("","ext_window","width=500,height=400,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,left=100,top=20,screenX=50,screenY=50")}</script><!-- checking for JavaScript support in the client browser --><noscript> <b><font color="red">You need to enable JavaScript in your browser.</font></b></noscript>
Mike
Nice. I was able to cause overflow on Stack overflow :p
Mike
Or find out what the actual HTTP POST is that is made during logon and make that directly with Mechanize.
i5m
A: 

You could try Webrat. Webrat doesn't understand JavaScript as far as I know.

TK