Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How to click on 2nd link (both have same Xpath)

by Anonymous Monk
on Jan 02, 2013 at 14:45 UTC ( #1011282=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Happy New Year.

I have a humble question for you on mech:firefox.

I have 2 links which have a same xpath pattern. I need to click on the 2nd one. By doing the below code, I am Clicking default first. I need to click the 2nd. How could it be possible..?

$mech->click({ xpath => "//a[\@title=\"Go to the next page\"]", synchronize => 0 });

Thx.

Comment on How to click on 2nd link (both have same Xpath)
Download Code
Re: How to click on 2nd link (both have same Xpath)
by Corion (Pope) on Jan 02, 2013 at 14:54 UTC

    You can have indices in XPath expressions. I suggest you use them. See the "predicates" in the XPath specification.

    As an alternative, you can do the same in Perl, by first finding all relevant links, storing them in an array and then passing the second entry in the array as an argument to ->click().

      Thx Corion... :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-08-30 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls