2

I am trying to run webdriverio with PhantomJS/Chrome to load a page and then grab the window object for use with other scripts. For some reason I am unable to get the window object. Everytime I get, I end up seeing output like this:

Title is: XXXXX
{ state: 'pending' }

Using the following script:

var webdriverio = require('webdriverio');
var options = {
    desiredCapabilities: {
        browserName: 'chrome',
        logLevel: 'verbose'
    }
};

var client = webdriverio.remote(options);

client
     .init()
     .url('https://xxxx.com')
     .waitUntil(function () {
         return client.execute(function () {
             return Date.now() - window.performance.timing.loadEventEnd > 40000;
        }).then(function (result) {
             console.log(window);
             return window;
         });
     })
     .end();

Does anyone know how I can fix my code so that the window object is returned to my NodeJS console app after the page is completely loaded?

Thanks!

2 Answers 2

6

Window is an object in the browser's DOM, so it's only available inside of the 'execute' function. If you wanted access to it, you could return it from your 'execute' function:

return client.execute(function () {
     return window;
}).then(function (result) {
     console.log(result);
});
0

This work as well:

browser.execute('return window');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.