Reading JavaScript variables using Selenium WebDriver February 28, 2023 by Tarik All you have to do is: Object val = js.executeScript("return returnFoo();"); That will give you what you are looking for.