How would you read a JavaScript variable in Selenium WebDriver?
It's anything but difficult to get to any JavaScript variable from the Selenium Webdriver test contents. Just you have to utilize the beneath Java code bit.
//Initialize the JS object.
JavascriptExecutor JS = (JavascriptExecutor) webdriver;
//Get the present site title.
String sitetitle = (String)JS.executeScript("return document.title");
System.out.println("My Site Title: " + sitetitle);