javascript - CasperJS doesn't evaluate jQuery method -


i injected jquery casperjs:

phantom.injectjs('./utils/jquery/jquery-2.1.4.js'); 

but when try evaluate jquery code, ignored: example:

function dragndropalerttoactivity() {     var tt = casper.evaluate(function() {         $('div[id^="scheduler-alert-grid"] table:contains(blue alert)')[0].simulate("drag-n-drop", {             dragtarget: {                 dx: 71,                 dy: 71,                 interpolation: {                     stepcount: 2                 }             }         });         return "done";     });     casper.echo(tt); }; 

calling method like: casper.test.begin(function(){...}). test executed using: casperjs test tests

the output says $ cannot found.

why ignore jquery, when write simple selector?

the phantom.injectjs() documentation says (emphasis mine):

injects external script code specified file phantom outer space.

which means jquery not injected page context try use it.

you can either use manual approach (ref):

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

or normal casperjs approach injects script on every page visit:

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

or

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

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -