我正在试着检查我的网页中是否存在一个选择器,但是casperjs一直没有找到它。
我试过两种方法:
1.无需等待
casper.then(function() {
// search for 'casperjs' from google form
this.test.assertExists('#search-form', 'the element exists');
// this.test.assertExists('.glyphicon.glyphicon-plus', 'the element exists');
});2.等待选择器
casper.waitForSelector('#search-form', function() {
this.echo("I'm sure #search-form is available in the DOM");
});3.另一种等待方法
casper.waitFor(function check() {
return this.evaluate(function() {
return $('#search-form').length == 1;
});
}, function then() { // step to execute when check() is ok
test.assertExists('#search-form', 'tabs area is found');
}, function timeout() { // step to execute if check has failed
this.echo("Timeout: page did not load in time...").exit();
});到目前为止,他们中没有人能找到选择者。并且这个选择器是从html加载的,它不是由javascript插入的。
有什么想法吗?
发布于 2014-05-12 14:46:45
好吧,我想你应该检查一下你的选择器是否在你的网页上:
casper.then(function(){
console.log(this.getPageContent());
});命令-pipe输出-:casperjs test yourFile.js > seePageContent.html
或者您可能更喜欢这种方式(如果需要,可以等待):
casper.then(function(){
this.wait(3000,function(){
var fs = require('fs');
fs.write("seePageContent.html", this.getPageContent(), 'w');
});
});这样你就可以知道你的元素是否存在。如果没有,那么您的前一步是错误的。
https://stackoverflow.com/questions/23610083
复制相似问题