Почему простой JavaScript не работает в CasperJS?
Я новичок в CasperJS. Как придешьthis.echo(this.getTitle());
работает ноconsole.log("Page Title ", document.title);
не делает? Кроме того, почему не работает мой document.querySelector? У кого-нибудь есть хорошее объяснение? Где в документации по CasperJS я могу найти ответ?
Вот мой код:
var casper = require('casper').create();
var url = 'http://www.example.com/';
casper.start(url, function() {
this.echo(this.getTitle()); // works
this.echo(this.getCurrentUrl()); // works
});
casper.then(function(){
this.echo(this.getCurrentUrl()); // works
console.log("this is URL: ", document.URL); // doesn't work
console.log("Page Title ", document.title); // doesn't work
var paragraph = document.querySelectorAll('p')[0].innerHTML;
console.log(paragraph); // doesn't work
});
casper.run();
РЕДАКТИРОВАТЬ: Я использую casper.thenEvaluate и casper.evaluate сейчас, и он все еще не работает. Есть идеи?
var casper = require('casper').create();
var url = 'http://www.example.com/';
casper.start(url, function() {
this.echo(this.getTitle()); // works
this.echo(this.getCurrentUrl()); // works
console.log('page loaded: '); // works
});
casper.thenEvaluate(function(){
var paragraph = document.querySelectorAll('p')[0].innerHTML; // doesn't work
console.log(paragraph); // doesn't work
console.log("Page Title ", document.title); // doesn't work
});
casper.run();