Reading JavaScript variables using Selenium WebDriver
Solution 1:
All you have to do is:
Object val = js.executeScript("return returnFoo();");
That will give you what you are looking for.
Solution 2:
No JavaScript functions need be defined. Nor is alert()
needed.
Object result = js.executeScript("return globalVar");
For Python:
result = driver.execute_script("return globalVar")