3

I am currently working with nodejs and phantomjs (using this bridge: https://github.com/sgentle/phantomjs-node/blob/master/samples/test_phantom.js) and my simple phantomjs function isn't working properly. I'm wondering if it is a compability error with phantomjs and nodejs, or am I just making a blatant phantomjs error? I am trying to grab the input form on the google homepage. Here is the relevant code:

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();
        });


    });
});

The error I am receiving:

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

Thanks much!

user3175505
  • 123
  • 1
  • 6
  • Are you sure the document body has loaded when you are running that `evaluate` code? – jraede Jun 05 '14 at 20:10
  • Keep in mind that google changes the page including ids for different viewports/useragents. It is possible that no such id exists. Maybe you do your tests with another site like SO. – Artjom B. Jun 05 '14 at 22:47

0 Answers0