Mechanizing a Javascript function in Ruby

Posted: June 2, 2009 in Web Development
Tags: , , ,

I encountered an interesting issue with this couple of months ago.

Using mechanize you can select or click form dom elements, submit forms and automate
interaction with websites. But let’s say there’s a case when you select an element
or click on a button – and it’s calling a Javascript function to get the result.

In such cases, you can’t directly get the result by mechanizing the element. Rather
you could just follow two simple steps to get the result,

1 – View the page source or inspect the element using firebug.

2 – Do the exact thing in your ruby script that the javascript function is doing.

for example: If the javascript function is trying to load the data by opening another
Url then open that url in your Ruby script. Here, you can by pass the mechanizing step
and get the result directly!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s