Skip to content Skip to sidebar Skip to footer

Casperjs Doesn't Evaluate Jquery Method

I injected jQuery to CasperJS: phantom.injectJs('./utils/jquery/jquery-2.1.4.js'); but when I try to evaluate some jQuery code, it is ignored: example: function dragNdropAlertToA

Solution 1:

The phantom.injectJs() documentation clearly says (emphasis mine):

Injects external script code from the specified file into the Phantom outer space.

Which means that jQuery is not injected into the page context where you try to use it.

You can either use the manual approach (ref):

casper.then(functiondoSomething() {
    this.page.injectJs('relative/local/path/to/jquery.js');
    var tt = this.evaluate(function () {
        // ...
    });
});

or the normal CasperJS approach which injects the script on every page that you visit:

var casper = require("casper").create({
    clientScripts: ["relative/local/path/to/jquery.js"]
});

or

casper.options.clientScripts.push("relative/local/path/to/jquery.js");

Post a Comment for "Casperjs Doesn't Evaluate Jquery Method"