【发布时间】:2015-07-22 14:43:45
【问题描述】:
我将 jQuery 注入 CasperJS:
phantom.injectJs('./utils/jquery/jquery-2.1.4.js');
但是当我尝试评估一些 jQuery 代码时,它被忽略了: 示例:
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);
};
调用方法如:casper.test.begin(function(){...})。
测试使用:casperjs test tests
输出显示找不到$。
当我写一个简单的选择器时,为什么它会忽略 jQuery?
【问题讨论】:
-
看起来不错。你的脚本的输出是什么?请注册
resource.error、page.error、remote.message和casper.page.onResourceTimeout活动 (Example)。可能有错误。 -
它找不到变量
$,我应该以某种方式额外传递它吗? -
为什么不使用
casper.options.clientScripts? -
它说我尝试访问只读变量,如果我使用'casper.options.clientScript'
标签: javascript jquery testing casperjs