1

I am trying to access global variables using webdriver with javascript.

my code:

this.Then(/^I read global var$/, function (selectedElement) {
    readGlobalVar(window.location.href);
});

function readGlobalVar(varName){
return varName;
}

the error: ReferenceError: window is not defined

0

2 Answers 2

1

The code is running on node and not in the browser so when you pass window.location.href to your readGlobalVar function it fails because window is not defined.

If what you need is to wait until the url matches certain value you should consider until.urlMatches

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I want to have access to global variables, not href in particular, some that are specific to my app.
0

Assuming that you are using this module

The JS execution environment of Node and the JS execution environment of the browser you are controlling with Selenium are different. They don't share variables between them. You communicate between them by passing messages through the webdriver.

In order to read a variable from the currently loaded page, you need to use the execute method to pass some JS into the page.

browser.execute(function () {
    return window.location.href;
}).then(function (result) {
    console.log(result.value);
});

1 Comment

thx, no webdriverio because of some issues with cucumberjs integration.

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.