bmakan
bmakan

Reputation: 421

CasperJS not confirming dialog

Using casperjs 1.1.4 with slimerjs 1.0.0-beta1 and Firefox 58.0b11.

I have the following code:

casper.then(function() {
    casper.setFilter(
        'page.confirm',
        function(msg) {
            return true;
        },
    );
    casper.evaluate(function() {
        const $btn = $('#btn');
        $btn.click();
    });
});
casper.then(function() {
    test.assertUrlMatch(
        /www.google.com/,
        'Success',
    );
});

The confirm dialog appears after clicking on the button. However, for some reason the confirm dialog is never actually confirmed even though I return true all the time.

Upvotes: -1

Views: 117

Answers (1)

Rippo
Rippo

Reputation: 22424

When asking for a new resource e.g. a button clickit is always good practice to use a casper.waitForUrl

In your case something like:

casper.waitForUrl("google.com", function() {
    test.assertUrlMatch(
        /www.google.com/,
        'Success',
    );
});

See all the wait for api methods

Upvotes: 0

Related Questions