本文介绍了页面未完全加载/渲染onLoadFinished火灾时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Phantomjs来检查我的申请。我在看该页面包含了很多组件,由Angularjs供电。我的测试服务器很慢。在 onLoadFinished 事件,我使用成像渲染网页:

I'm using Phantomjs to examine my application. The page I am looking at includes a lot of components and is powered by Angularjs. My test server is slow. In the onLoadFinished event, I am imaging the web page using render:

page.onLoadFinished = function(response) {
    console.log(response, page.url);
    if (page.url.indexOf("login") == -1) {
        page.render('zoot.png');
        phantom.exit();
    }
};

我的问题是, zoot.png 仅包括网站的菜单栏。菜单栏的文字和静态图像呈现,但图标是X的。主要的页面区域是空白的。文本化版本号显示在预计右下角。

My issue is that zoot.png only includes the site's menu bar. The menu bar's text and static images are rendered but the icons are Xs. The main page area is blank. A textual version number appears in the lower right which is expected.

它看起来像当渲染发生的页面没有完全绘制。有没有意思是完成,准备使用其他事件?

It looks like the page was not fully drawn when the render happened. Is there another event that means "done and ready for use"?

推荐答案

您可能会找到一种方法here当角呈现完毕注册事件,但如果你愿意等待的时间静态量可能不是必要的:

You might find a way here to register an event when angular has finished rendering, but it might not be necessary if you are willing to wait a static amount of time:

page.onLoadFinished = function(response) {
    console.log(response, page.url);
    if (page.url.indexOf("login") == -1) {
        setTimeout(function(){
            page.render('zoot.png');
            phantom.exit();
        }, 1000);
    }
};

您也可以使用以明确等待它表示负载结束时选择的外观。

You can also use waitFor to explicitly wait for the appearance of a selector which denotes the end of the load.

注意 page.open(URL); page.onLoadFinished = finishedFunction; 相同 page.open(URL,finishedFunction)

这篇关于页面未完全加载/渲染onLoadFinished火灾时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:23