[PETDANCE - Tue Mar 25 00:50:27 2003]:
Show quoted text> A lot of html pages does not put name attribute on the button tag.
> so, click() should be callable either by "name" (existing feature)
> or by "type" (new ) or by "value". signature could be
> $agent->click("name_attr", "name_value");
> $agent->click("type_attr", "type_value");
> $agent->click("value_attr", "value_value");
>
>
Here's a patch that adds a click_button() method that takes a key/value pairs. You can
click a button by name, value, or index.
Andy may want to merge this into the existing click() method.
No tests yet.
Linda
--- /usr/local/share/perl/5.8.0/WWW/Mechanize.pm Tue Feb 17 22:45:12 2004
+++ Mechanize.pm.new2 Tue Feb 17 22:44:29 2004
@@ -708,6 +708,65 @@
return $self->request( $request );
}
+=head2 $mech->click_button( ... )
+
+Has the effect of clicking a button on a form by specifying its name,
+value, or index. Its arguments are a list of key/value pairs. Only
+one of name, number, or value must be specified.
+
+=over 4
+
+=item * name => name
+
+Clicks the button named I<name>.
+
+=item * number => n
+
+Clicks the I<n>th button in the form.
+
+=item * value => value
+
+Clicks the button with the value I<value>.
+
+=item * x => x
+=item * y => y
+
+These arguments (optional) allow you to specify the (x,y) coordinates
+of the click.
+
+=cut
+
+sub click_button {
+ my( $self, %args ) = @_ ;
+
+ for ( keys %args ) {
+ if ( !/^(number|name|value|x|y)$/ ) {
+ $self->warn( qq{Unknown click_button_form parameter "$_"} );
+ }
+ }
+
+ for ($args{x}, $args{y}) { $_ = 1 unless defined; }
+ my $form = $self->{form};
+ my $request;
+ if ($args{name}) {
+ $request = $self->{form}->click($args{name}, $args{x}, $args{y});
+ } elsif ($args{number}) {
+ my $input = $form->find_input(undef, 'submit', $args{number});
+ $request = $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) {
+ $request = $input->click($form, $args{x}, $args{y});
+ last;
+ }
+ $i++;
+ }
+ }
+
+ return $self->request( $request );
+}
+
=head2 $mech->submit()
Submits the page, without specifying a button to click. Actually,