yungblud
yungblud

Reputation: 418

Why won't CasperJS accept a redirect request after clicking on a link?

I'm having more Casper troubles, this time I've told Casper to click on a href that will redirect it to a page that will redirect it to the twitter app auth page:

    var casper = require('casper').create({
    verbose: false,
    logLevel: 'debug',
    waitTimeout: 10000
});
phantom.cookiesEnabled = true;

casper.start('http://foo.bar', function afterstart() {
    if (this.exists('#back-to-top')) {
        this.echo('BOOYA! foo.bar is loaded', 'INFO');
    } else {
        this.echo('Page didnt load, something went all screwy.', 'ERROR');
    }
});

casper.then(function signin() {
    this.click('a[href="/sys/login"]' );
 });

casper.then(function tellsignin() {
    if (this.exists('#not-logged-in ')) {
        this.echo("I clicked on twitter login button, so now the twitter login page is loaded.", 'INFO');
    } else {
        this.echo('Twitter login link didnt work, something went wacky');
    };
});

When I run it, the console error output is this, plus some other stuff that isn't important:

Test file: testingtest.js                                                       
BOOYA! foo.bar is loaded
Twitter login link didnt work, something went wacky

I've tried looking up explanations, and found this group thread, but it unfortunately doesn't provide any answers for my problem. Does anyone know any possible reasons why Casper isn't redirecting?

Upvotes: 2

Views: 4311

Answers (1)

yungblud
yungblud

Reputation: 418

I've resolved the issue thanks to all of your help and support, lol! What happened is that the tellsignin function was being executed before the browser had time to be redirected to the twitter app auth page, so I just added a this.waitForText('Authorize foo-bar app to use your account?') to the signin function.

Upvotes: 10

Related Questions