mrl
mrl

Reputation: 1536

Selenium Web Driver access Javascript global variable in Jquery

I am trying to run a functional test in Python using Selenium, and I want to retrieve the value of a global variable in Javascript that has been declared on a certain page.

Normally browser.execute_script("return globalVar;") works fine, but this variable is declared within $(document).ready(function(){, and Selenium can't locate it.

So Selenium can return the variable when it's declared like this:

var globalvar = 0;
$(document).ready(function(){
});

but not like this:

$(document).ready(function(){
    var globalvar = 0;
});

Is there anyway I can use Selenium to return the value of the javascript global variable from within the Jquery document ready?

Upvotes: 0

Views: 1731

Answers (1)

Lyn Headley
Lyn Headley

Reputation: 11598

That's not a global variable. It is local to the scope of the anonymous function. So no, you can't access it.

Upvotes: 2

Related Questions