How would you read a JavaScript variable in Selenium WebDriver?

1.2K    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

Interviews

Parent Categories