Currently, I am attempting to retrieve the string output from JavascriptExecutor called within Java for the first time. While I have looked at various posts on SO, none seem to detail how to successfully extract the string into Java.
After scouring the internet, the common consensus is that the following code should suffice:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return document.title");
String CatchS = js.toString();
System.out.println("Output from JavaScript:" + CatchS);
However, instead of the expected result, all I receive is
Output from JavaScript: FirefoxDriver: firefox on XP (506d8fd0-0ce2-4693-8e56-2166a77a5136)
Interestingly, this output mirrors what you would get if you intentionally pass invalid JavaScript to JavascriptExecutor (indicating it isn't functioning correctly).
I have attempted the alternative solutions proposed in Get Value from ExecuteScript from JavaScriptExecutor, and even tried returning a simple 'hello world'. Unfortunately, none of these methods seem to work. What could I be overlooking?
It is crucial for the real code I am attempting to integrate to return a string value once operational. Your assistance is greatly appreciated. Thank you.