Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 });


Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-02-25 06:18 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (312 votes). Check out past polls.