slloyd has asked for the wisdom of the Perl Monks concerning the following question:

How do I get the id value from a WWW::Mechanize::Link object? Or can I call click and pass it the link object?
my @links = $fftab1->find_all_links(id_contains=>'VDEL_'); #say "Links:@links"; foreach my $link (@links){ my $id=$link->attrs->{id}; #returns nothing say "clicking Link Item $id"; $fftab1->click(id=>$id, synchronize => 0); select(undef,undef,undef,1); next; }
s/te/ve/

Replies are listed 'Best First'.
Re: WWW::Mechanize::Link get id from attrs (firefox find_link_dom)
by Anonymous Monk on Feb 11, 2015 at 23:55 UTC

    How do I get the id value from a WWW::Mechanize::Link object? my $id=$link->attrs->{id}; #returns nothing

    That must mean there is no ID

    Or, if there really is an ID, Corion didn't make that part work :) (unlikely but possible, in which case try find_link_dom)

    Or can I call click and pass it the link object?

    Try  ...->click( $link, synchronize => 0 ); where $link is either either from find_link_dom or from find_link

        Um, http://search.cpan.org/perldoc/WWW::Mechanize::Link#$link->attrs()?

        see href and id in hash below

        $ cat alinkswithhrefsandids.html <html> <body> <a href="http://example.com/first+one" id="first"> one </a> <a href="http://example.com/second+two" id="second"> two </a> <a href="http://example.com/third+three" id="third"> three </a> $ mech-dump --links file:alinkswithhrefsandids.html http://example.com/first+one http://example.com/second+two http://example.com/third+three $ perl -MData::Dump -MWWW::Mechanize -e " $u=WWW::Mechanize->new; $u-> +get( qw/ file:alinkswithhrefsandids.html /); dd( $u->links ); " do { my $a = bless([ "http://example.com/first+one", "one", undef, "a", bless(do{\(my $o = "file:alinkswithhrefsandids.html")}, "URI::file +"), { href => "http://example.com/first+one", id => "first" }, ], "WWW::Mechanize::Link"); ( $a, bless([ "http://example.com/second+two", "two", undef, "a", \${$a->[4]}, { href => "http://example.com/second+two", id => "second" }, ], "WWW::Mechanize::Link"), bless([ "http://example.com/third+three", "three", undef, "a", \${$a->[4]}, { href => "http://example.com/third+three", id => "third" }, ], "WWW::Mechanize::Link"), ); }