Subject: | value doesn't support multiple checkboxes with the same name. |
I appear to be having difficulty attaching files, so I'll include some
cut and paste here as well.
I'm attempting to walk through a tick every checkbox with a given name.
I don't care what the value is, I want to tick all of them. I thought
I'd start by getting the value, so that I could pass the name and value
to tick. The HTML is pretty straight forward:
<form method="POST" action="test.cgi">
<input type="checkbox" name="check" value="1111" >1111
<input type="checkbox" name="check" value="2222" >2222
<input type="checkbox" name="check" value="3333" >3333
<input type="checkbox" name="check" value="4444" >4444
<input type="checkbox" name="check" value="5555" >5555
</form>
And the code is as well:
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
use Data::Dumper;
my $mech = WWW::Mechanize->new();
$mech->get("http://localhost/~jarich/abc.html");
print Dumper $mech->forms();
print scalar $mech->value("check", 1);
Unfortunately for all field numbers I pass to value I get a undefined
value, when I expected to receive "1111" or "2222". Interestingly, if I
edit the HTML to say that the field is "checked" then value returns the
expected value "1111" etc.
The data dump for each unchecked data dump looks like:
bless( {
'current' => 0,
'menu' => [
{
'seen' => 1,
'value' => undef,
'name' => 'off'
},
{
'value' => '1111',
'name' => '1111'
}
],
'name' => 'check',
'type' => 'checkbox'
}, 'HTML::Form::ListInput' ),
If the checkbox is checked however it looks like:
bless( {
'current' => 1,
'menu' => [
{
'value' => undef,
'name' => 'off'
},
{
'seen' => 1,
'value' => '3333',
'name' => '3333'
}
],
'name' => 'check',
'type' => 'checkbox'
}, 'HTML::Form::ListInput' ),
where the value of current and the hash with the "seen" value appears to
map to whether the checkbox is checked upon loading.
I'm hoping a work around will be to walk through the structure and set
current => 1 for each element with the name "check".
Subject: | test.pl |
#!/usr/bin/perl -w
use strict;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get("http://localhost/~jarich/abc.html");
use Data::Dumper;
print Dumper $mech->forms();
print scalar $mech->value("check", 1);