Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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


Comment on How to click on 2nd link (both have same Xpath)
Download Code
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-10-04 18:08 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (104 votes), past polls