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

I'm trying to automate my program to submit this form by pressing the "Calculate Time Only" button.
use WWW::Mechanize; open(OUTFILE, '>c:\Perl output.txt') or die "Can't open output.\n"; open(UPSOUT, '>c:\Perl UPSoutput.txt') or die "Can't open output.\n"; $url = "http://wwwapps.ups.com/calTimeCost?loc=en_US&WT.svl=SubNav"; my $mech = WWW::Mechanize->new(); $mech->get($url); $form1 = "form1"; $mech->form_name($form1); $mech->set_fields( origPostal =>"53213", destPostal =>"60056", ); $mech->field("transitTimeOnly", "Calculate Time Only"); $mech->submit($form1); my $results2 = $mech->content; print OUTFILE $results2; die;
I get no errors, but the content of $mech is still the initial page. Why can't I submit this? How do I get it to submit?

Replies are listed 'Best First'.
Re: Submitting form input type = image
by ptum (Priest) on Jan 10, 2006 at 20:51 UTC

    I think because the form is invoked by an input image, you need to use the $mech->click('transitTimeOnly') method, passing the name of the button you want to click.

    The WWW::Mechanize documentation describes it fairly well.


    No good deed goes unpunished. -- (attributed to) Oscar Wilde
Re: Submitting form input type = image
by GrandFather (Saint) on Jan 10, 2006 at 21:05 UTC

    Try $mech->click ('transitTimeOnly'); rather than $mech->submit($form1);. You can omit $mech->field("transitTimeOnly", "Calculate Time Only");.


    DWIM is Perl's answer to Gödel
Re: Submitting form input type = image
by bcdeery (Novice) on Jan 10, 2006 at 23:22 UTC
    This worked. I guess that was a lot simpler than I thought. Thanks!