3
我想检查选择器是否存在于我的网页中,但casperjs从来没有找到它。PhantomJS/CasperJS AssertExists()失败
我已经试过两种方法:
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插入的。
任何想法?
+1有人可能认为这可能已过时,但有时一个页面将具有不同的DOM元素,具体取决于userAgent或在浏览器或phantomjs中分解。 –
你说得对,我有一个问题,默认情况下,CasperJs用Linux **推出了移动版本的网站**。 userAgent对设备奇怪地未知,导致casper切换到移动版本。我注意到它只是通过检查DOM(并用'this.capture()'确认它)。 Marcelosalloum,你可以等待一个元素出现,如果它不存在,它将无法工作。最好知道什么是现在,而不是什么不是。 – Fanch