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

Hello Monks!

I'm trying to use WWW::Mechanize to click a "TAB" button at : http://spiedigitallibrary.org/ebooks/spies/kbart

The button's source code:

</table> <br><br> <input type="submit" name="action" value ="Excel"> <input type="submit +" name="action" value ="CSV"> <input type="submit" name="action" value ="TAB"> <input type="submit" +name="action" value ="HTML"> </form>

I'm using the following line:

$mech->click_button (value => "TAB");

but get an error:

.Can't call method "header" on an undefined value at ....app/perl-5.10.1/lib/site_perl/5.10.1/WWW/Mechanize.pm line 2381.

What can be the problem?
Thank you in advance!
Danny

Replies are listed 'Best First'.
Re: Using Mechanize to click a button
by moritz (Cardinal) on Mar 17, 2011 at 10:59 UTC

      Sorry, here it is

      my $mech = WWW::Mechanize->new(); print "Accessing $url\n"; $mech->get($url); print "Downloading the file..."; $mech->click_button (value => "TAB"); $mech->save_content( $full_path ); print "Done.\n";
      Thanks! output:
      Accessing http://spiedigitallibrary.org/ebooks/spies/kbart?isAuthorize +d=no Downloading the file...Can't call method "header" on an undefined valu +e at /exlibris/sfx_ver/app/perl-5.10.1/lib/site_perl/5.10.1/WWW/Mecha +nize.pm line 2381.
      If I hash out the code related to the button the main mage is saved without problem.

        The WWW::Mechanize documentation says that click_button works on the "current Form", which might be the source of your problem. There's a search form before the form you are interested in.

        So you might need to invest some effort into selecting the right form.