Euphe
Euphe

Reputation: 3699

CasperJS: page error

I am trying to login into a website, but I get a page error midway. When I am on my browser it works fine.

Page Error: TypeError: 'undefined' is not a function (evaluating '$(document.bod
y).appendChild( iframe )')

It's strange as jQuery is injected into the page and I don't understand the problem.

Here is the code of the step after which the error occurs

casper.then(function LogIn() { // LOG IN
        this.page.setCookies('');
        if (this.page.injectJs('X:/XXX/JS/jquery-latest.min.js')){this.echo('Injected jQuery')}
        //this.echo(this.getCurrentUrl(), "info");
        this.fill('form[name="logon"]',
            {
                'username': username,
                'password': password,
                'redir': "http://***/",
                'msg': '',
                'emailauth': '',
                'loginfriendlyname': '',
                'captchagid': '-1'
            }
        ,false);
      //  this.evaluate(function(){DoLogin();})
       // this.echo('Loginform:' + this.fetchText('#loginForm'))
        if( this.exists('form input[type="submit"]')){
            this.echo('Exists');

            this.evaluate(function(){
                document.getElementById('Login').click();
            })
          //  this.evaluate(function(){document.querySelector('form[name="logon"]').submit()})
            //this.click('form input[type="submit"]');

        }
        else {
            this.echo('Doesnt exist')
        }
        this.wait(2000)
});

To be precise the error occurs right after this

  this.evaluate(function(){
                    document.getElementById('Login').click();
                })

Upvotes: 1

Views: 459

Answers (1)

EpokK
EpokK

Reputation: 38092

Try to replace :

this.evaluate(function(){
   document.getElementById('Login').click();
});

By :

this.click('#Login');

Upvotes: 2

Related Questions