Issue with submit_form and multiple select boxes

79 views
Skip to first unread message

Mike Tonks

unread,
Jan 6, 2012, 6:08:39 AM1/6/12
to WWW::Mechanize users
Hi folks,

I've just signed up to the list but I've been using WWW:Mechanise for
a while, particularly with Test::WWW::Mechanise and
Test::WWW::Mechanise::PSGI and I'm very happy with it. We use this to
test our perl web application full stack, and it's totally great.

So first of all a big thanks to the authors and maintainers!

My current issue is this bit of code:

$mech->submit_form_ok( {
form_name => 'myform',
fields => {
field1 => '111',
field2 => '222',
field_multi => ['aaa', 'bbb'],
},
}, "Submit form ok");

sadly this doesn't work, so I have to do:

$mech->field( field_multi => ['aaa', 'bbb'] );

$mech->submit_form_ok( {
form_name => 'myform',
fields => {
field1 => '111',
field2 => '222',
},
}, "Submit form ok");


As you can see it's a bit messy. I think I could override the
submit_form_of method to check the field values for arrayrefs and
automagically call the $mech->field method.

However before I do that I thought I'd contact the list to see if
anyone has a better idea or fancies doing a patch at a higher level.
Seems like the submit_form method must have the same issue so would
probably be better fixed there.

As I looked into it I realised that $mech->submit_form uses $mech-
>set_fields( $name => $value ... ) has an intentional feature that
interprets an array ref as an attempt to set one of multiple fields
with the same name. Sadly this breaks my attempt to set a single
field that accepts multiple values.

Then I found that this works:

$mech->submit_form_ok( {
form_name => 'myform',
fields => {
field1 => '111',
field2 => '222',
field_multi => [['aaa', 'bbb'], 1],
},
}, "Submit form ok");

as it get's around the feature above. So I guess I have a solution.

I'll float this anyway to see if anyone has interesting ideas :)

cheers,

mike

Reply all
Reply to author
Forward
0 new messages