无法让我的angularJS应用程序与phantomJS一起工作

无法让我的angularJS应用程序与phantomJS一起工作,angularjs,phantomjs,Angularjs,Phantomjs,在我的AngularJS(1.2.9版)应用程序上使用Win8上最新的phantomJS(1.9.7),我无法与我的应用程序交互。 我一直在得到消息 InvalidElementStateError:{“errorMessage”:“元素当前不可交互,不能被操作” 当我调用render()时,我得到一个空图像 如果我在调用render()之前给脚本添加了一个超时,我会得到一个完全混乱的页面视图: 作为比较,这是它在任何其他浏览器中的外观: 我用来截屏的脚本- var page = requi

在我的AngularJS(1.2.9版)应用程序上使用Win8上最新的phantomJS(1.9.7),我无法与我的应用程序交互。
我一直在得到消息
InvalidElementStateError:{“errorMessage”:“元素当前不可交互,不能被操作”

当我调用
render()
时,我得到一个空图像

如果我在调用
render()
之前给脚本添加了一个超时,我会得到一个完全混乱的页面视图:

作为比较,这是它在任何其他浏览器中的外观:

我用来截屏的脚本-

var page = require('webpage').create();
page.open('http://localhost/app/account#/login', function() {
    setTimeout(function() {
        page.render('login-phantom.png');
        phantom.exit();
    }, 1000);
});
还有其他人遇到过类似的情况吗?
我应该检查什么?

超时并没有真正的帮助(除非您将其设置为超长时间),因为网络响应速度随时间而变化。最好的选择是有一个变量,在数据加载时通知(在角度侧)已完成,例如
$scope.dataStatus='ready'
。然后您可以向html上的元素添加
数据状态
属性,并从phantomjs端对其进行轮询,以查看数据是否已加载。您可以在
页面内进行轮询。在phantomjs上评估

Matsko已经写了一篇关于这些内容的文章

因此,您的phantomjs代码可能看起来像:

var page = require('webpage').create();
page.open('http://localhost/app/account#/login', function (status) {
    var delay, checker = (function() {
        var html = page.evaluate(function () {
            var status = document.getElementById('status');
            if(status.getAttribute('load-status') == 'ready') {
                return document.getElementsByTagName('html')[0].outerHTML;
            }
        });
        if(html) {
            clearTimeout(delay);
            page.render('login-phantom.png');
            phantom.exit();
        }
    });
    delay = setInterval(checker, 100);
});
虽然您的html可以是:

<html>
    <head>...</head>
    <body>
        <div id="status" load-status="{{ dataStatus }}"></div>
    </body>
</html>

...
希望有帮助