However, it turns out that select will ALWAYS think that it can select entry 1, even if the list is empty. In other words, even when the html looks like this:my $ans = 1; # or whatever. while ($ans) { %pickme = ( n => 1 ); #yes, this should be outside the while. So s +ue me ;-) $ans = $mech->select( 'server', \%pickme ); if ($ans) { $inputobj = $mech->current_form()->find_input( 'remove', 'subm +it'); die 'argh! Cannot find delete button on the iSCSI Access page! +' unless $inputobj; $ans = $mech->click_button( input => $inputobj ); } } print "Done! Now, accept the empty list\n"; # ok, now accept a (hopefully) empty list of allowed accessors $inputobj = $mech->current_form()->find_input( 'accept', 'submit'); die 'argh! Cannot find Accept button on the iSCSI Access page!' unless + $inputobj; $ans = $mech->click_button( input => $inputobj );
The above code will get '1' back from select and go running on forever. Not a good thing...<td> <input type="hidden" name="serverList" value=""> <select size="10" name="server" style="width: 330px"> </select> </td>
It seems to me that the first form should have worked (see the Mechanize page under select() for details of why - won't bore everyone here with that), so I'm looking at the Mechanize and Form code to see why it allows a 'select' of 1 when there are no items.while ($ans) { %pickme = ( n => 2 ); eval { $ans = $mech->select( 'server', \%pickme ); }; if ($ans eq 1) { $inputobj = $mech->current_form()->find_input( 'remove', 'subm +it'); die 'argh! Cannot find delete button on the iSCSI Access page! +' unless $inputobj; $ans = $mech->click_button( input => $inputobj ); } else { $ans = 0; } } %pickme = ( n => 1 ); $ans = $mech->select( 'server', \%pickme ); $inputobj = $mech->current_form()->find_input( 'remove', 'submit'); die 'argh! Cannot find delete button on the iSCSI Access page!' unless + $inputobj; $ans = $mech->click_button( input => $inputobj ); print "Done! Now, accept the empty list\n"; # ok, now accept a (hopefully) empty list of allowed accessors $inputobj = $mech->current_form()->find_input( 'accept', 'submit'); die 'argh! Cannot find Accept button on the iSCSI Access page!' unless + $inputobj; $ans = $mech->click_button( input => $inputobj );
When there is nothing in the select list, the above test still passes! I note, when stepping through the code, that if I print $val when I'm looking at the 'big if' above, I get a blank line, BUT defined($val) is true!for (@{$self->{menu}}) { if ((defined($val) && defined($_->{value}) && $val eq $_-> +{value}) || (!defined($val) && !defined($_->{value})) ) { $cur = $i; $disabled = $_->{disabled}; last unless $disabled; } $i++; }
In reply to Is this a bug in mechanize::select(), or am I just confused? (or something else) (answer: bad html) by rustycar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |