Short Two solutions below -- Don't specify the event to wait for (so that its default list is used), or use click
method which does wait on its own, instead of submit_form
.
I see the same problem with form_submit
, and with the synchronize
method. Either the next call still gets the page being submitted, or the script hangs with synchronize
(used, correctly, as in Borodin's answer). I test with a site which does a bit of work as a form is submitted.
Wrapping calls in synchronize
is borne with some subtleties. What events are fired or not is not clear and can also be affected (earlier in the code). I found that the code works when no events are specified in the call, and the default list of events()
is thus checked for.
mech->synchronize( sub {
$mech->submit_form( with_fields => { log => 'admin', pwd => 'password' } );
});
$mech->save_content('after_submit.html');
The following call gets the correct page.
The documentation never mentions waiting with form
methods, so some synchronization is needed. However, the click
method does wait, by default (one can change that with synchronize
option).
So I found this to solve the problem as well: Fill the form and click
it.
# Get the page with the form
$mech->fields( log => 'admin', pwd => 'password' );
$mech->click( name => 'Login' ); # whatever the name is
$mech->save_content('after_submit.html');
The next call after click
gets the actual next page.
In case the form has no name on <input>
, for example, this works as well
$mech->click_button(input => 'submit');