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

K, go easy, Im a nub trying to learn Mech. I keep having problems with this section and the field name. Using this code:
$browser->form_number(1); $browser->field("zipCode", $module_name); $browser->click();
I keep getting: No such field 'zipCode' at C:/Perl/lib/WWW/Mechanize.pm line 1247 I use firebug and inspect the field to get the name such as: input onkeyup="clearForm()" onfocus="enableObject('searchButton',1,'Search')" value="" size="3" maxlength="5" id="zipCode" name="zipCode"/ Stuck...

Replies are listed 'Best First'.
Re: WWW::Mechanize problem
by Gangabass (Vicar) on May 29, 2008 at 02:09 UTC

    May be you inspect wrong form? Try to find needed form by name and after that use field() property.

      OK, here is exactly what Im trying to do. Im trying to make the program ask the user for a zip code they want to do a search on to find all the nearest insurance agencies in the area. Here is the site I am trying to use http://www.unitrinspecialty.com/us/locator/. Here is the code so far..
      use strict; use warnings; print "What zip code? \n"; my $module_name = <STDIN> or die "Must specify module name on command line"; use WWW::Mechanize; my $browser = WWW::Mechanize->new(); $browser->get("http://www.unitrinspecialty.com/us/locator/"); $browser->form_number(1); $browser->field("zipCode", $module_name); $browser->click();

        Go to the website in a browser. Select 'View Source'. Search for the word 'form'. Discover that form #1 is the search box in the upper right hand corner, and you are attempting to set non-existent fields in the wrong form.

        After that, either try $mech->form_number(2), or better yet $mech->form_name( 'zipForm' ) or even $mech->form_with_fields( 'zipCode' ).


        www.jasonkohles.com
        We're not surrounded, we're in a target-rich environment!