Pala Bhaskar Pala Bhaskar - 7 months ago 8
Javascript Question

error occured while executing the javascript code in java

I want to execute javascript code in java. So I Wrote the code as shown in below. But during execution it fails at middle line. saying error as 'missing ; before statement '.

JavascriptExecutor js = (JavascriptExecutor)driver;

String g=(String) js.executeScript("var r = confirm('r u ready');"+"if(r==true) { Var b='ok'; } return b;");

System.out.println(g);

Answer
"(function() {var r,b; r = confirm('r u ready'); if(r == true) { b='ok'; } return b;})()"