matharumanpreet00
matharumanpreet00

Reputation: 309

Casperjs cannot access same global objects as in from browsers console

I am new to Casperjs, phantomjs .I have been trying hard to create some page automation to login and take some steps in a CMS but i am having issues with accessing the global window variables from casperjs evaluate() function. the below example is just checking jquery on Google. Jquery exists in the page and some other global functions but i can't access them from casperjs.

casper.start('https://www.google.ca/#hl=en', function() {

// search for 'casperjs' from google form
this.fill('form[action="/search"]', { q: 'casperjs' }, false);
});

casper.then(function() {
  this.evaluate(function jquery() {
      console.log('looking for jquery ---');
      console.log($ + 'exists');
  });
});

getting error - `ReferenceError: Can't find variable: $

How can i fix this ?

Any help is appreciated :)

Upvotes: 0

Views: 225

Answers (1)

Alex Muravyov
Alex Muravyov

Reputation: 512

For use jQuery in casperjs inject script in page, something like:

var casper = require('casper').create({
    some code here,
    clientScripts:  ['/path/to/jquery.js'],
});

Upvotes: 1

Related Questions