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.