【发布时间】:2014-06-10 21:05:10
【问题描述】:
我正在尝试使用 casperjs 捕获页面加载时间。有问题的页面受登录保护。这是我目前所拥有的:
var casper = require('casper').create();
// Enter the login page, fill up the form and submit it
casper.start('https://example.net/login', function () {
// Fill the form
this.fill('form[name=signin]', {
'user': 'username',
'passwd': 'password'
}, false);
// Submit the form by clicking the submit button
this.then(function() {
this.click('#sign_in');
});
});
// Now on the loggedin page click the link of page for which response time is needed
casper.then (function() {
var start = Date.now();
this.click ('#pageLink');
// Measure response time of this page
var end = Date.now();
this.echo (end - start);
});
casper.run();
我几乎可以说这是错误的方法,因为我可能应该等待页面加载然后捕获结束时间。但是在 casper js 文档页面上,我没有找到任何可以让我知道页面何时完全加载的内容。寻找结束标签并查看它是否已加载是否有意义?
【问题讨论】:
-
是单页应用吗?如果没有,那么您可以在下一个
casper.then块中捕获var end = Date.now();,因为它是一个步进函数,它只会在页面从上一步完全加载时继续执行。
标签: casperjs