javascript - How Do I use jQuery in CasperJS? -


casper.start(url, function() {      casper.page.injectjs('c:/users/mike/documents/n1k0-casperjs-bc0da16/jquery-1.10.2.min.js');     var names = $('span.author-name');     this.echo(names);     this.exit(); } 

referenceerror: can't find variable: $

what do? i've tried when creating casper instance:

var casper = require('casper').create({      // i've tried both commented lines below      // clientscripts: ['c:/users/mike/documents/n1k0-casperjs-bc0da16/jquery-1.10.2.min.js']     // clientscripts: ['includes/jquery-1.10.2.min.js'] }); 

you have evaluate jquery code in browser context using casper.evaluate

execute code if using browser console.

var namecount = this.evaluate(function() {     var names = $('span.author-name')     return names.length; }); this.echo(namecount); 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -