Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

WWW::Mechanize::Firefox follow link with javascript

by Anonymous Monk
on Dec 10, 2012 at 13:25 UTC ( [id://1008098]=perlquestion: print w/replies, xml ) Need Help??

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

I am using WWW::Mechanize::Firefox and want to follow a link on a page that uses javascript. I have tried using the follow_link function, Firefox shows the linked page but the Perl code hangs.

$mech->follow_link( n => 3 );

If I add synchronize => 0 then it continues but the html in $mech->contents is not updated.

$mech->follow_link( n => 3, synchronize => 0 );

I have also tried using the click call with the following code but I get the error message "Can't locate object method "__click" via package "WWW::Mechanize::Link"..."

my @links = $mech->links(); $mech->click({dom => $links[3]});

And with the following code the error message is "Can't locate object method "click" via package "WWW::Mechanize::Link"..."

my @links = $mech->links(); $links[3]->click();

Any help with the correct method to use would be very much appreciated.

Replies are listed 'Best First'.
Re: WWW::Mechanize::Firefox follow link with javascript
by Corion (Patriarch) on Dec 10, 2012 at 14:17 UTC
    You will have to inspect the HTML and Javascript of the page you're automating. As an alternative, you can also use a method that returns DOM objects instead of using a method that returns WWW::Mechanize::Link objects, as per the documentation.

      Thanks for the help. For the benefit of anyone else with this problem, the solution was to use the find_all_links_dom() function which returns the correct sort of link objects to use with the click function.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1008098]
Approved by Lotus1
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found