in reply to Mechanize Firefox xpath link with same name

You can add an index to XPath queries if you want the nth element:

//parent/a[@class="nav"][4]

Note that the following does not work because numbering is according to parent/ancestor, not in the results:

//a[@class="nav"][4]

If you don't have a suitable common ancestor, you will have to find the element by using the text() function or extract the element using Perl:

my @nav= $mech->xpath('//a[@class="nav"]'); $mech->click( $nav[3] );

Replies are listed 'Best First'.
Re^2: Mechanize Firefox xpath link with same name
by depojones (Initiate) on Jul 15, 2014 at 13:04 UTC
    Thanks for your prompt reply. The example you provided worked as expected. Thank you once again!