http://www.perlmonks.org?node_id=575256

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

I'm trying to fill out a form in a nasty page (baaad HTML!) using Corion's handy utility WWW::Mechanize::Shell.

The form includes this source:

<form name="someForm" method="post" action="/some_form.do"> ... <input type="checkbox" name="dayOfWeek" value="SUN" >Sun <input type="checkbox" name="dayOfWeek" value="MON" >Mon <input type="checkbox" name="dayOfWeek" value="TUE" >Tue <input type="checkbox" name="dayOfWeek" value="WED" >Wed <input type="checkbox" name="dayOfWeek" value="THU" >Thurs <input type="checkbox" name="dayOfWeek" value="FRI" >Fri <input type="checkbox" name="dayOfWeek" value="SAT" >Sat ... </form>
which comes up in WWW::Mechanize::Shell as:
dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|SUN/Sun] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|MON/Mon] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|TUE/Tue] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|WED/Wed] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|THU/Thurs] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|FRI/Fri] dayOfWeek=<UNDEF> (checkbox) [*<UNDEF>/off|SAT/Sat ]
Everything I've tried like:

tick dayOfWeek SUN or tick or on or SUN or tick SUN on

just returns errors like:

|SUN (checkbox)dayOfWeek> [] tick dayOfWeek SUN Illegal value 'tick dayOfWeek SUN' for field 'dayOfWeek' at /usr/lib/p +erl5/site_perl/5.8.0/WWW/Mechanize/FormFiller.pm line 124
and
|SUN (checkbox)dayOfWeek> [] tick Illegal value 'tick' for field 'dayOfWeek' at /usr/lib/perl5/site_perl +/5.8.0/WWW/Mechanize/FormFiller.pm line 124
and
|SUN (checkbox)dayOfWeek> [] tick SUN on Illegal value 'tick SUN on' for field 'dayOfWeek' at /usr/lib/perl5/si +te_perl/5.8.0/WWW/Mechanize/FormFiller.pm line 124
If I just hit <enter> on all of them so they are not ticked then I get this in the script output:
$formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' ); $formfiller->add_filler( 'dayOfWeek' => Fixed => '' );
Which looks perfectly braindead :o( :o(

The man page just says:

tick Set checkbox marks Syntax: tick NAME VALUE(s) If no value is given, all boxes are checked. untick Remove checkbox marks Syntax: untick NAME VALUE(s) If no value is given, all marks are removed.

and nothing else mentions checkboxes...

When I check the first two boxes in Firefox and look at the result using LiveHTTPHeaders I see this is being posted:

... &dayOfWeek=SUN&dayOfWeek=MON& ...

Is it possible to get WWW::Mechanize to send the same?

I tried this:

#!/usr/bin/perl use warnings; use strict; use WWW::Mechanize; use WWW::Mechanize::FormFiller; my $agent = WWW::Mechanize->new( autocheck => 1 ); my $formfiller = WWW::Mechanize::FormFiller->new(); $agent->form(1) if $agent->forms and scalar @{$agent->forms}; $agent->get('http://server/page_with_form/'); $agent->form(1) if $agent->forms and scalar @{$agent->forms}; $agent->form_number(1); $formfiller->add_filler( 'dayOfWeek' => Fixed => 'SUN' ); $formfiller->fill_form($agent->current_form); $agent->click('');
and I get this back:
$ ./try.pl Illegal value 'SUN' for field 'dayOfWeek' at /usr/lib/perl5/site_perl/ +5.8.0/WWW/Mechanize/FormFiller.pm line 124
Lovely! :o( If I get cheeky and try something like:
$formfiller->add_filler( 'dayOfWeek' => 'SUN' => 'on' );
I get:
$ ./try.pl Can't locate WWW/Mechanize/FormFiller/Value/SUN.pm in @INC (@INC conta +ins: /usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl .) at (eval 23) line 2. BEGIN failed--compilation aborted at (eval 23) line 2. WWW::Mechanize::FormFiller::load_value_class('SUN') called at +/usr/lib/perl5/site_perl/5.8.0/WWW/Mechanize/FormFiller.pm line 65 WWW::Mechanize::FormFiller::add_filler('WWW::Mechanize::FormFi +ller=HASH(0x995ebdc)','dayOfWeek','SUN','on') called at ./try.pl line 30
GRRR!!!

what am I doing wrong?

Is it to do with bug #2700: Set/Reset multiple checkboxes?

Or is the bad HTML making WWW::Mechanize / WWW::Mechanize::Shell bork? (that's kind of what it looks like to me)

Edited by planetscape - added readmore tags

( keep:0 edit:29 reap:0 )