Skip to content

click_button( input => $input ) does not press the passed submit button #428

Description

@oalders

Summary

Calling click_button( input => $input ) with an HTML::Form::Input object does
not actually press that submit button. The button's own name/value pair (e.g.
submit=Go) is missing from the resulting request, even though the correct
input object was passed in.

This is currently documented as a TODO test in t/local/click_button.t
(the "click by object reference" subtest), where it produces:

ok 1 - 'Found the submit button' isa 'HTML::Form::Input'
ok 2 - Named the right thing, too
not ok 4 - Correct button was pressed # TODO Calling ->click() on an object doesn't seem to use the submit button.
#   at t/local/click_button.t line 126.
#                   'http://[::1]:PORT/formsubmit?session=1&query=(empty)&cat=cat_foo&cat=cat_bar&upload='
#     doesn't match '(?^:submit=Go)'

Note the request URI omits submit=Go, so the submit input that was explicitly
passed never contributes its value.

Reproduction

From t/local/click_button.t:

my $clicky_button = $form->find_input( undef, 'submit' );  # isa HTML::Form::Input
my $res = $mech->click_button( input => $clicky_button );
# Expected the request to include submit=Go; it does not.

Relevant code

lib/WWW/Mechanize.pm, in click_button():

elsif ( $args{input} ) {
    $request = $args{input}->click( $form, $args{x}, $args{y} );
}

By contrast, the name/number/id branches resolve an input via the form and
click it, and those paths transmit the button's name/value correctly. The
input => branch clicks the passed object directly but the button's name/value
does not end up in the request.

Expected behaviour

click_button( input => $submit_input ) should press that specific submit
button and include its name=value pair in the request, matching the behaviour
of the other selector forms.

Notes

The behaviour is already captured by a failing TODO test in the
"click by object reference" subtest of t/local/click_button.t; that test can be
un-TODO'd once this is fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions