Google, как было известно, не был благоприятен для личинки. Для этого, чтобы работать, необходимо установить UserAgent.
Это было проверено под CasperJS-1.0.0 и PhantomJS-1.8.0
var casper = require('casper').create({
pageSettings: {
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Chrome/25.0.1349.2 Safari/537.21'
}
});
var x = require('casper').selectXPath;
casper.start('http://google.co.in/', function() {
//search for 'casperjs' from Google form
this.test.assertExists(x('//*[@type="text"]'), 'the element exists');
this.test.assertExists({
type: 'xpath',
path: '//*[@type="text"]'
}, 'the element exists');
});
casper.run(function() {
//echo results in some pretty fashion
this.echo('').exit();
});
Можно посетить http://whatsmyuseragent.com/ видеть, каков ваш текущий UserAgent.
Update: Removed CasperJS-1.0.0 code in favor of backwards-compatible code.