为什么可以'我在Casperjs中使用indexOf
Why can't I use indexOf in Casperjs?
我有以下代码(试图用casperjs运行它):
var casper = require('casper').create({
viewportSize: {width: 1024, height: 768},
verbose: true,
logLevel: 'debug',
onError: function(self, m) { // Any "error" level message will be written
console.log('FATAL:' + m); // on the console output and PhantomJS will
self.exit(); // terminate
}
});
casper.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
casper.start('http://casperjs.org/', function() {
var pageText = this.evaluate(function() {
return document;
});
if(pageText.indexOf('Casper') > -1) {
console.log("Already logged in");
} else {
console.log("Not logged in");
}
});
//
casper.run();
我收到以下输出:
casperjs test.js
[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[debug] [phantom] opening url: http://casperjs.org/, HTTP GET
[debug] [phantom] Navigation requested: url=http://casperjs.org/, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://casperjs.org/"
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/2 http://casperjs.org/ (HTTP 200)
TypeError: 'undefined' is not a function (evaluating 'pageText.indexOf('Casper')')
C:/wamp/www/tw/tw.js:16
C:/casperjs/modules/casper.js:1553 in runStep
C:/casperjs/modules/casper.js:399 in checkStep
有人能告诉我为什么它不能评估pageText.indexOf('Cancer')吗?我不知道:(
确实如此。pageText在那里未定义。非常感谢。这是一个伪问题。很抱歉
相关文章:
- CasperJS在使用sendKeys时不会上传文件
- 为什么indexOf在这个js代码中不起作用
- 我如何才能让CasperJS和PhantomJS在约塞米蒂玩得很好
- Angularjs通过过滤器获取indexOf
- indexOf具有2个参数
- 从node.js向CasperJS传递参数数组
- .indexOf()不适用于特定元音
- CasperJS在每个URL中循环
- 对字符串使用IndexOf来挑选某些单词
- 如果window.location.href.indexOf('player=1')添加样式
- inArray,indexOf在二维数组中
- 当已经使用CasperJS选择了css类元素时,断言该类的存在
- Casperjs等待资源
- CasperJS(phantom 1.9.7),从昨天起就无法连接https
- CasperJS填充表单-输入名称有方括号
- 如何测试选择器是否存在于CasperJS中
- 使用CasperJS测试多个HTML页面
- casperjs对表单使用waittentivisible
- 为什么我得到“;没有方法'indexOf'"在ExtJS4.2中尝试在网格上使用缓冲渲染器时出错
- 为什么可以'我在Casperjs中使用indexOf