检测Angularjs中的页面呈现状态

时间:2015-05-19 04:25:45

标签: c# angularjs selenium-webdriver phantomjs

我需要一种方法来检查AngularJS何时完全完成浏览器渲染,以便我的无头浏览器PhantomJS可以抓取并返回整页html。

通常情况下,我会使用某种类型的Id,hnt元素的类名来为phantomjs检测页面是否呈现,但在SPA中像angularjs一样很难做同样的事情,因为我无法检查是否所有部分都在页面已完成渲染。

using (IWebDriver driver = new PhantomJSDriver())
{
    var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
    string url = String.Format("http://localhost:12345/{0}", fragment);
    driver.Navigate().GoToUrl(url);

    var header = wait.Until(ExpectedConditions.ElementExists(By.Id("footer")));  >> bad because footer is always there, not in angularjs code
    content = driver.PageSource;
}

所以我想知道Angularjs是否有办法检测到网站已完成渲染,然后我可以将其标记为<input id="renderStatus" name="renderStatus" ng-if="renderStatus>0" type="hidden" value="{{renderStatus}}">

更新:我试过$ viewContentLoaded和$ stateChangeSuccess但没达到我想要的效果

app.run(['$rootScope', '$q', 
    function ($rootScope, $q) {
        $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
            $rootScope.$on('$viewContentLoaded', function (event) {
                $rootScope.renderStatus = 1;
            });
        });
    }
]);

0 个答案:

没有答案