我试图检查我的网页中是否存在选择器,但 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 插入的。
有任何想法吗?
好吧,我认为您应该检查您的选择器是否在您的网页中,如下所示:
casper.then(function(){
console.log(this.getPageContent());
});
命令-管道输出-:casperjs test yourFile.js > seePageContent.html
或者您可能更喜欢这种方式(如果需要,请等待):
casper.then(function(){
this.wait(3000,function(){
var fs = require('fs');
fs.write("seePageContent.html", this.getPageContent(), 'w');
});
});
这样您就知道您的元素是否存在。如果不是,那么你之前的步骤是错误的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)