Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Javascript Navigation with WWW::Mechanize::Firefox

by Matt™ (Acolyte)
on Sep 20, 2012 at 14:40 UTC ( #994675=perlquestion: print w/replies, xml ) Need Help??
Matt™ has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, Need your help for Javascript Navigation with WWW::Mechanize::Firefox

I need to navigate to next page of this URL

How can i click on "Onclick" in a code like this <li title="Next Page" class="next" onclick=";30:&quot;,&quot;_next&quot;,event);"><span class="alt">Next Page</span></li>

I can use $mech->post(WWW::Mechanize) in this case but wont get the actual page that i need(the html should look same as in the website). It will return only the Post page and should parse using Regex.

Pls be kind to answer my question Monks, I am new to WWW::Mechanize::Firefox. Thanks in advance :)

Replies are listed 'Best First'.
Re: Javascript Navigation with WWW::Mechanize::Firefox
by Corion (Pope) on Sep 20, 2012 at 14:58 UTC

    Just a short reply, as I can't reply in longer detail.

    I recommend using the ->click method. Also have a look at the Examples, Cookbook and Troubleshooting documents in WWW::Mechanize::Firefox.

      Thanks Corion, Its working with the same code $mech->click({xpath => '//li[@class="next"]', synchronize=>0, });

      Thanks for your valuable time. :)

      Thanks Corion, but it failed.

      I am not sure whether its a correct way but I tried like this, $mech->click({xpath => '//li@class="next"', synchronize=>0, }); , and I am getting like "No elements found for '//li@class="next"'"

      Can you pls suggest a way. Thanks in advance.

        I am getting like "No elements found found

        When that happens, dump the innerHTML of body and verify the lack of such an element

        print $body =~ m{(<li.*?class="next".*?</li>)};

        Using firebug, if I turn off javascript, there is no search results, no next button

        But if I turn on javascript,  $x('//li[@class="next"]'); returns two nodes

        /html/body/form/div[2]/div[2]/div[2]/div/table/tbody/tr/td[2]/div/tabl +e/tbody/tr[2]/td/span/div/ul/li[5] /html/body/form/div[2]/div[2]/div[2]/div/table/tbody/tr/td[2]/div/tabl +e/tbody/tr[25]/td/span/div/ul/li[5]

        Also, maybe the search results are still loading

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://994675]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-03-20 06:26 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.