0

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?

1 Answer 1

2

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

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

1 Comment

Wow, I've been working in Jquery for too long. I completely looked over the fact that the document ready is a function itself.

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.