1

I'm new to casperjs,the evaluate function is not getting executed

casper.start('https://piedmont.taleo.net/careersection/2/moresearch.ftl?lang=en',function(){

    casper.page.injectJs('/Users/manoj/apply_robots/jquery/jquery-2.1.4.min.js');
    this.echo(this.getTitle());

    this.wait(3000,processPage);
    this.echo("before processPage");

    });

    function processPage()
    {

        this.echo("inside processPage");
        var c = [];

        c = this.evaluate(getJ);
        this.echo(c);


    }

    function getJ(){
        this.echo("inside getJ");
        var jobs = [];
            var names = $('table#requisitionListInterface\\.listRequisition tr[id$=row]');
            __utils__.echo(names);

            for (var i = 0, row; row = names[i]; i++) {
                var $p = $.parseHTML(row.cells[1].innerHTML);
            }

            jobs.push(names);
            return names.length;


    }
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
simplyblue
  • 2,279
  • 8
  • 41
  • 67
  • possible duplicate of [Message does not appear when called from evaluate method](http://stackoverflow.com/questions/25135598/message-does-not-appear-when-called-from-evaluate-method) – Artjom B. Jun 24 '15 at 17:04

1 Answers1

1

Probably

this.echo("inside getJ");

is the problem in your case, cause "this" in evaluate function is not the casper object, but probably the Window object. And since evaluate is executed in sandbox, it does not throw errors out.

Good luck

  • you know how to call casperjs click from evaluate function? – simplyblue Jun 24 '15 at 14:51
  • 1
    casper.evaluate(function(reason) { document.querySelector('#ctl00_Main_ctl00_btnUpdate_IdentityNotes1_txtReasonNotes').value = reason; document.querySelector('#ctl00_Main_ctl00_btnUpdate_sb').click(); }, config.reasonAutorize); – Angel Paraskov Jun 24 '15 at 15:11
  • That last bit is wrong. You can't pass the `casper` object into the page context, because it cannot be serialized. – Artjom B. Jun 24 '15 at 17:04