本文介绍了casperJS失败注入jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道我遇到了怎么回事
Does anyone know how come I am encountering
[warning] [phantom] Failed injecting %s client side.
Failed injecting includes/jquery-1.10.2.min.js client side
当我已包含
'includes/jquery-1.10.2.min.js'
在Casper构造函数中。有人在此处发布了类似的问题:,但我不明白他们如何在他们的解决方案中加入casper.evaluate():
within the Casper constructor. Someone posted a similar question here: https://groups.google.com/forum/#!msg/casperjs/hY4ziaoXIEE/YFi8Sj4JysMJ, but I do not understand how they have incorporated the casper.evaluate() in their solution:
casper.then( function() {
this.evaluate(function($) {
console.log($('title').text());
}
});
推荐答案
我不记得曾经能够使用CasperJs构造函数的clientScripts选项注入脚本。相反,我总是找到以下工作。
I don't remember ever being able to inject scripts using the clientScripts option of the CasperJs constructor. Instead I have found the following works for me always.
casper = require('casper').create();
casper.start();
casper.open('some url');
casper.then(function doSomething() {
this.page.injectJs('relative/local/path/to/jquery.js');
var items = this.evaluate(function () {
return $('div.someClass'); // jquery here
});
});
这篇关于casperJS失败注入jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!