[Mechanize-users] Clicking image maps?

Aaron Patterson aaron at tenderlovemaking.com
Mon May 28 16:12:49 EDT 2007


Hey Peter!

On Mon, May 28, 2007 at 09:25:20AM +0200, Peter Szinek wrote:
> Hello all,
> 
> I am trying to click image maps ("area" nodes), and while Perl's 
> mechanize treats "a", "area", "frame", "iframe" and "meta" tags as 
> links, it seems to me that Ruby's Mechanize thinks only "a" tags can be 
> links (at least my little experiment, namely:

Looks like I've missed area nodes.  Thats a bug, and I'll add it to the
next release.

> 
> page.links.each {|link| puts link.node.name}
> 
> on a page with "area" nodes all over tells me).
> 
> Is there a way to click "area" nodes? Or at least is there a method of 
> Mechanize::Page which returns all the nodes (which would make this 
> relatively easy).

If you find the HPricot node from the page, you should be able to click
it as long as it has an 'href' or a 'src' attribute.

> 
> 2 related questions:
> 
> - if I have a HPricot node, which has a 'href' or 'src' attribute, can I 
> click it?

Yes.  Just pass the node to WWW::Mechanize#click.  It will check for an
href attribute, src attribute, then try calling an href method.  In that
order.

> - if I have an URI (as a String), can I click it? (or navigate to that URI).

Yes.  WWW::Mechanize#get takes a string.

Hope that helps!

--
Aaron Patterson
http://tenderlovemaking.com/


More information about the Mechanize-users mailing list