On Mar 14, 2013, at 8:27 AM, G M wrote: > > Hi all, > > I managed to get the problem with my script not connecting to the page last > night, turned out my web host wouldn't allow it. Got that sorted. Filling > in the form should be really simple but I'm getting the following error when > trying to set the "acOriginAirport" field, I thought it might be to do with > the javascript on the page but I'm entering a value that the form accepts. > > The form is being found on the page as I can dump out $agent->forms(); > > Any ideas anyone? > > Status: 500 > Content-type: text/html > > Software error: > Can't call method "value" on an undefined value at > /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1407. > > > This is my script: > #!/usr/bin/perl -w > > use strict; > use CGI qw(:standard); > use CGI::Carp qw(warningsToBrowser fatalsToBrowser); > use WWW::Mechanize; > use HTML::TokeParser; > use Data::Dumper; > print "Content-type: text/html\n\n"; > print "setting up mech<br />"; > my $agent = WWW::Mechanize->new(); > $agent->agent_alias('Windows Mozilla'); > print "mech setup"; > > $agent->get('http://www.easyjet.com/en/searchpod.mvc/showborderless?aclwidth=279'); > print "setting up airports <br />"; > $agent->field("acOriginAirport", "Glasgow GLA");
I have not used WWW::Mechanize, but from reading the documentation, it would seem you must call $agent->form_number($number) with a form number before making any calls to field(). Line 1407 of Mechanize.pm is part of the field method: sub field { my ($self, $name, $value, $number) = @_; $number ||= 1; my $form = $self->current_form(); if ($number > 1) { $form->find_input($name, undef, $number)->value($value); } else { if ( ref($value) eq 'ARRAY' ) { $form->param($name, $value); } else { $form->value($name => $value); # line 1407 } } } The current_form() method is returning null because you have not specified (with a call to form_number()) which form you are using. Hence the error message you are seeing. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/