Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

WWW::Mechanize::Firefox follow link with javascript

by Anonymous Monk
on Dec 10, 2012 at 13:25 UTC ( #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.

Comment on WWW::Mechanize::Firefox follow link with javascript
Select or Download Code
Re: WWW::Mechanize::Firefox follow link with javascript
by Corion (Pope) 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
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? | Other CB clients
Other Users?
Others lurking in the Monastery: (16)
As of 2015-07-02 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (45 votes), past polls