基本的phantomjs问题 - getElementById无法正常工作

时间:2014-06-05 19:49:06

标签: javascript node.js phantomjs

我目前正在使用nodejs和phantomjs(使用这个桥:https://github.com/sgentle/phantomjs-node/blob/master/samples/test_phantom.js),我的简单幻像功能不能正常工作。我想知道它是否是与phantomjs和nodejs的兼容性错误,还是我只是犯了一个明显的phantomjs错误?我想抓住谷歌主页上的输入表格。以下是相关代码:

phantom.create(function (ph) {
ph.createPage(function (page) {
    page.open("https://www.google.com/", function (status) {
        console.log("opened", status);
        /*
        Page is succesfully opened
        */
        page.evaluate(function() {
            var x; //meaningless code

            function funny() {
                var q = document.getElementById("gbqfq").value; //if q = document.title it works properly
                return q;
            }
            x = funny();
            return x;
        },
        function(result) {
            console.log(result);
            ph.exit();
        });


    });
});

我收到的错误:

phantom stdout: TypeError: 'null' is not an object (evualuating 'document.getElementById("gbqfq").value')

非常感谢!

0 个答案:

没有答案