nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use the synchronize method like so:

$mech->get('http://example.com/wp-login.php'); $mech->submit_form( with_fields => {log => 'admin', pwd => 'password'} +); $mech->synchronize( 'DOMConentLoaded', sub {print Dumper($self->title( +)); }); exit;

The title of the newly loaded page prints but then the script just hangs. It never exits. What am I missing?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: How to use synchronize method with WWW::Mechanize::Firefox?
by Corion (Patriarch) on Mar 27, 2016 at 07:42 UTC

    You have a typo in your event:DOMConentLoaded is likely meant to be DOMContentLoaded.

    The program hangs because your callback never performs any action. The callback you pass to ->synchronize is supposed to click on a button.

Re: How to use synchronize method with WWW::Mechanize::Firefox?
by Anonymous Monk on Mar 27, 2016 at 07:41 UTC
    You are missing a valid event, you are waiting for an event that doesnt exist an will never occur check your spelking and try again
Re: How to use synchronize method with WWW::Mechanize::Firefox?
by nysus (Parson) on Mar 27, 2016 at 10:21 UTC

    Oops on the typo. But even without the typo, I have the same issue.

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      So where does your callback perform an action, like clicking?

        OK, I reread your previous post. It has to click on a button? I will try that.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

        Tried:

        $self->synchronize( 'DOMContentLoaded', sub { $self->click_button( nam +e => 'wp-submit' ); } );

        I still get same results. The next page loads but then browser hangs.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

        Also tried $self->synchronize( 'DOMContentLoaded', sub { $self->click( {selector => '#wp-submit'} ); } );

        Same results.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

        I've also tried the following:

        $self->synchronize( 'DOMContentLoaded', sub { $self->submit_form( with +_fields => {log => 'admin', pwd => 'password'} ) } );

        The submit_form gets called and the next page loads but then the script just hangs.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks