我想单击submit按钮,等待下一个页面加载,然后在第二个页面上获取html。我执行了启动,然后运行,但then步骤仍然在第一页上运行。有什么想法吗?
var casper = require('casper').create();
var site = 'http://www.example.com';
var data = {};
casper.start(site, function() {
this.evaluate(function() {
$('input[type="submit"]:first').click();
});
});
casper.then(function() {
data.body = this.evaluate(function() {
var rows = $('#content table:first tbody tr');
var listings = rows.eq(3).text();
var count = rows.eq(4).text();
return {
listings: listings,
count: count
};
});
});
casper.run(function() {
this.echo(data.body.listings);
this.exit();
});
发布于 2012-09-24 20:20:06
这只能部分解决您的问题,但您可以确认已使用waitFor进入第二个页面。例如:
this.waitFor(function check() {
return (this.getCurrentUrl() === PAGE_2_URL);
},
function then() { // step to execute when check() is ok
this.echo('Navigated to page 2', 'INFO');
},
function timeout() { // step to execute if check has failed
this.echo('Failed to navigate to page 2', 'ERROR');
});
发布于 2014-07-11 04:11:23
使用waitForResource等待页面加载完成是一个好主意,请参阅此处的文档documentation
示例:
casper.waitForResource(function checkAuth(validcredentials) {
return validcredentials;
}, function onReceived() {
if (authTitle !== this.getTitle()) {
this.log('Autenticação realizada com sucesso, aguarde...');
} else {
// this.capture('pic3.png');
this.log('Usuario ou senha invalidos!', 'ERROR');
this.die('User or password invalids!', 1); }
});
发布于 2012-08-29 06:17:39
我的doubleclick也有类似的问题。确保click事件被实际激发。我怀疑这就是在相同的内容中运行下一步的原因。
https://stackoverflow.com/questions/12024280
复制相似问题