0

i have a simple script but the problem is i have empty DOM and cant get any data. What am i doing wrong ?

This is my script:

var casper = require('casper').create({
        verbose: true,
        logLevel: 'error',
        pageSettings: {
            userAgent: 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36',
            javascriptEnabled: true
        },
        clientScripts: [
            'js/jquery-2.1.4.min.js'
        ]
    }),
    utils = require('utils');

function getMaxPages() {
    return $('#sportbetPageSelectorPanel').find('ul.lil li.lil-item').eq(-2).text();
}

casper.on('remote.message', function (msg) {
    this.echo('Remote: ' + msg);
});

casper.on("page.error", function(msg, trace) {
    this.echo("Error: " + msg, "ERROR");
});
casper.start('https://example.com/');

casper.then(function () {
    var maxPage = casper.evaluate(getMaxPages);

    console.log('max pages: '+maxPage);
});

casper.run(function () {
    this.exit();
});

Console log: $ max pages: It's like the object #sportbetPageSelectorPanel does not exists. I tried even to log $('body').html() and got empty sting. Can anyone help me with this ?

vardius
  • 6,326
  • 8
  • 52
  • 97
  • (1)What PhantomJS version do you have? (2) Please register to the `resource.error`, `page.error`, `remote.message` and `casper.page.onResourceTimeout` events ([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf)). Maybe there are errors. – Artjom B. Sep 01 '15 at 11:24
  • i have phantomjs 1.8 and events are registerd i just ahvent psoted it here, updated question – vardius Sep 01 '15 at 11:26
  • So, what's the output? – Artjom B. Sep 01 '15 at 11:27
  • there are no errors: just max pages as an empty string – vardius Sep 01 '15 at 11:28
  • You really should update PhantomJS to either 1.9.7, 1.9.8 or 2.0.0. v1.8 is really old. Also, try [this](http://stackoverflow.com/a/26419531/1816580). – Artjom B. Sep 01 '15 at 11:29
  • i had phantomjs 2.0 but casper said it will not work with phantom >=1.9 so i had to downlaod 1.8 – vardius Sep 01 '15 at 11:30
  • CasperJS 1.1-beta3 supports up to 1.9.8. – Artjom B. Sep 01 '15 at 11:33
  • hey you know what? i found a solution, i swap phantomjs as you said to 2.0 but at bootstrap.js of casper i had to add the following `var system = require('system'); var argsdeprecated = system.args; argsdeprecated.shift(); phantom.args = argsdeprecated;` you can answer my question with that if you want. i will accept it. – vardius Sep 01 '15 at 11:36
  • No, you should determine what the problem was. Please register to the `resource.error` event in PhantomJS 1.x. – Artjom B. Sep 01 '15 at 11:38
  • i did, but it didnt print enything. i think the problem was in that bootstrap.js file. – vardius Sep 01 '15 at 11:41

0 Answers0