0

I'm attempting to make a jquery call via executeAsyncScript in Selenium using an anonymous function. I usually don't use anonymous functions so I think I have the syntax correct, however, I keep getting a syntax error: Exception:org.openqa.selenium.WebDriverException: missing ; before statement Googling the error message basically says it's a syntax issue, but I can't find my error.

Code:

 JavascriptExecutor js = (JavascriptExecutor) driver;
 String ex = "cb = arguments[ arguments.length - 1 ];\n"  +
         "(function(){String btn = \"jq(\\\"a[title='Import']\\\").click();\"}());\n" +
          "cb();";

 System.out.println(ex);
 js.executeAsyncScript(ex);

What println(ex) give me which looks correct:

cb = arguments[ arguments.length - 1 ];
(function(){String btn = "jq(\"a[title='Import']\").click();"}());
cb();

A second pair of eyes would be greatly appreciated to see what I'm doing incorrectly or not understanding. Thank you.

Just as a side note, we have overridden $ to be "jq" in our environment.

Trebor
  • 793
  • 3
  • 11
  • 37
  • 1
    Is `String btn` supposed to be javascript? – SimpleJ Jan 14 '15 at 23:51
  • Yes! Thank you. That might be the problem. Unfortunately, I'm using Java to write JavaScript and may be getting my syntax mixed up. I'll test that out. – Trebor Jan 14 '15 at 23:52

0 Answers0