2

Node.js App, selenium webdriver, Chrome headless. My app needs to scrape a list of websites and one of them has attached information to global window variable.

I have tried the following and it throws an error:

// .... more code to load page up to this point

driver.execute(function () {
    console.log(window.info);
    return window;
}).then(function (result) {
    console.log( "\n\ninfo from window object: " + util.inspect(result) );
}).catch( (err) => {
    console.error(" Caught Error for window: " + err);
});

// throws ERROR:  Caught Error for window: TypeError: command.setParameter is not a function

Is there a way to access the global window variable from Selenium (preferably headless, but if I should use head then I can try that) ?

1 Answer 1

3

nevermind, I found the answer.

the method is executeScript() and not execute().

driver.executeScript("return window.info")
      .then(function (result) {
            console.log( "\n\ninfo from window object: " + util.inspect(result) );
      }).catch( (err) => {
        console.error(" Caught Error for window: " + err);
      });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.