Subject: | Problem using click_button(value => ...) to get image buttons |
Date: | Fri, 29 Sep 2006 12:21:49 -0600 |
To: | bug-WWW-Mechanize [...] rt.cpan.org |
From: | Spencer Christensen <schristensen [...] backcountry.com> |
Hello all,
I have run into a situation where I need to click on a button for a
form and use $mech->click_button(value => 'Add to Cart');. The problem
comes in where, this button may be an <input type="submit .../> tag or
it could be <input type="image" .../> tag (meaning it isn't always the
same).
I have WWW::Mechanize version 1.20 installed and found that when
trying to click by value, Mech will only look at input objects of type
'submit' and doesn't look at objects of type 'image'.
I made some changes to my copy of WWW::Mechanize to handle image
buttons as well as submit buttons for this case. Below is the patch for
version 1.20 that I made. Let me know if there is a preferred method
for posting bugs/fixes like this. Thanks.
--- /usr/lib/perl5/site_perl/5.8.7/WWW/Mechanize.pm 2006-08-19
00:07:57.000000000 -0600
+++ /fedora/usr/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm
2006-09-29 11:37:22.000000000 -0600
@@ -1469,16 +1469,16 @@
$request = $args{input}->click( $form, $args{x}, $args{y} );
}
elsif ( $args{value} ) {
- my $i = 1;
- while ( my $input = $form->find_input(undef, 'submit', $i) ) {
- if ( $args{value} && ($args{value} eq $input->value) ) {
+ my @inputs = ( $form->find_input(undef, 'submit'),
$form->find_input(undef, 'image') );
+ foreach my $input (@inputs) {
+ if ( $input->value && ($args{value} eq $input->value) ) {
$request = $input->click( $form, $args{x}, $args{y} );
last;
}
- $i++;
- } # while
+ } # foreach
} # $args{value}
+ $self->warn( qq{No button found for click_button} ) unless ($request);
return $self->request( $request );
}
--
Spencer Christensen
Infrastructure Engineering Team Leader
(801) 746-7580 x101
www.Backcountry.com
We use the gear we sell.