I\'m using Selenium WebDriver (Java) and TestNG to do some testing on a website I created. In this website, I also have JavaScript and in some of the functions, it returns v
All you have to do is:
Object val = js.executeScript("return returnFoo();");
That will give you what you are looking for.
In Ruby you can use page.execute_script
to evaluate a JavaScript variable (if it is accessable from the scope of the web browser). It looks like there is a similar method in Java here.
Edit: This might be a use case that is more suited to a JavaScript unit testing framework such as Jasmine.
No JavaScript functions need be defined. Nor is alert()
needed.
Object result = js.executeScript("return globalVar");
For Python:
result = driver.execute_script("return globalVar")