How would you read a JavaScript variable in Selenium WebDriver?

996    Asked by ShawneeSteele in QA Testing , Asked on Feb 16, 2020
Answered by Shawnee Steele

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);

Your Answer


Parent Categories