Best Answer · By JanBask QA Expert
Answered on Feb 16, 2020
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);