I am trying to execute a javascript function from java code.
I used JavascriptExecutor from selenium package.
I tried below code
JavascriptExecutor js;
js.executeScript("let time;");
js.executeScript("time = 2;");
js.executeScript("function f(){console.log(time);}");
js.executeScript("f()");
This is output
Exception in thread "Thread 0"
org.openqa.selenium.JavascriptException: javascript error: f is not defined
Is there any way to execute the above script from java code? is it possible?