PhantomJS/CasperJS AssertExists()失败 [英] PhantomJS/CasperJS AssertExists() is failing
问题描述
我正在尝试检查网页中是否存在选择器,但casperjs找不到它.
I am trying to check wether a selector exists in my webpage but casperjs never finds it.
我尝试了两种方法:
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插入的.
None of them has been able to find the selector so far. And this selector is loaded from the html, it is not inserted by the javascript.
有什么想法吗?
推荐答案
好吧,我认为您应该像这样检查选择器是否在您的网页中:
Well, I think you should check if your selector is in your webpage like that :
casper.then(function(){
console.log(this.getPageContent());
});
命令-管道输出-:casperjs test yourFile.js > seePageContent.html
或者您可能更喜欢这种方式(如果需要,请稍候):
Or you might prefer this way (with a wait if needed) :
casper.then(function(){
this.wait(3000,function(){
var fs = require('fs');
fs.write("seePageContent.html", this.getPageContent(), 'w');
});
});
这样,您就知道您的元素是否存在.如果不是,则您的上一步是错误的.
That way you know if your element is present or not. If not, then your previous step is wrong.
这篇关于PhantomJS/CasperJS AssertExists()失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!