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

Hi perl monks, im a new soul looking for wisdom im making a simple WWW::Mechanize routine here it is my code:
#!/usr/bin/perl # use strict; use WWW::Mechanize; my $target = "http://www.somewebpage.com/subscription/showsubscribe"; my $mech = WWW::Mechanize->new(agent=>$useragent); $mech->get($target); my $response = $mech->click_button(value=>"subscriptionTop", value=>"loadingSubscript +ion();"); $mech->submit(); die "Error at '$target'\n", $response->status_line, "\n Aborting" unless $response->is_success; $response = $mech->response; for my $key ($response->header_field_names()) { print "response[$key] = ", $response->header($key), "\n"; } #print $mech->content;
then on my linux box im getting something like click_button: No form has been selected at ./mech.pl line 9 in the code of the webpage i have it is showing:
<input type="image" src="/image/suscribe-btn.png;jsessionid=uK6psR994V +LpkeMzmEEVte9n" onclick="loadingSubscription();" class="img_content_i +mg_home" id="subscriptionTop">
any tip of where it is my fault? im reading in the cpan about www::mechanize but i cant get how to click on this link thanks for your help!

Replies are listed 'Best First'.
Re: Click on "any" href
by choroba (Cardinal) on Mar 05, 2015 at 09:08 UTC
    onclick="loadingSubscription();"
    WWW::Mechanize doesn't support JavaScript.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Then with www::mechanize will be impossible right?

        Have a look at WWW::Mechanize::Firefox, which, as the name says, requires Firefox, and make sure to look at the "Incompatibilities" section of the documentation too.

Re: Click on "any" href
by vinoth.ree (Monsignor) on Mar 05, 2015 at 08:43 UTC

    Global symbol "$useragent" requires explicit package name at xxxxx.pl line 8.

    This is what I am getting when I execute your code.

    The WWW::Mechanize documentation says that click_button works on the "current Form", which might be the source of your problem. please check whether the button is in any form? if it is means try add below example code before click_button() and try.

    Ex:
    # select the first form and examine its contents $m->form_number(1); my $f = $m->current_form or die "Couldn't get first form!\n";

    All is well. I learn by answering your questions...
      yeah my mistake i forgot to erase the $useragent variable, regarding form it does not have anyform it is just a button in a landing page