Account Summary...">

By clicking the JavaScript link in Mechanize

I have it:

<a class="top_level_active" href="javascript:Submit('menu_home')">Account Summary</a>

I want to click this link, but when using link_to I get an error.

I tried:

bot.click(page.link_with(:href => /menu_home/))
bot.click(page.link_with(:class => 'top_level_active'))
bot.click(page.link_with(:href => /Account Summary/))

The error I get is: NoMethodError: undefined `[] 'method for nil: NilClass

+5
source share
3 answers

This is a javascript link. The mechanism will not be able to click on it, since it does not evaluate javascript. Excuse me!

Try to find out what happens in your browser when you click this link. Does it create a POST or GET request? What are the parameters that are sent to the server. Once you know this, you can emulate the same action in the script engine. Chrome dev / firebug tools will help.

, , javascript. watir-webdriver , phantomjs, casperjs, pjscrape .

+13

2 , , hrefs, , :

puts page.links.map(&:href)

, , , , . ajax. , :

page.link_with(:href => /menu_home/).click

, , , javascript.

+1

. , :

puts page.body
<HTML><SCRIPT LANGUAGE="JavaScript"><!--
     top.location="http://www.example.com/pages/myaccount/dashboard.aspx?";
// --></SCRIPT>
<NOSCRIPT>Javascript required.</NOSCRIPT></HTML>

, , , :

link_search = %r{top.location="([^"]+)"}
js_link = page.body.match(link_search)[1]
page = agent.get(js_link)
0
source

All Articles