public Object execute ( String scriptBody , Object [ ] parameters ) { try { asyncResult = new AsyncScriptResult ( ) ; Function function = createInjectedScriptFunction ( scriptBody , asyncResult ) ; try { page . executeJavaScriptFunction ( function , function , parameters , page . getDocumentElement ( ) ) ; } catch ( ScriptException e ) { throw new WebDriverException ( e ) ; } try { return asyncResult . waitForResult ( timeoutMillis ) ; } catch ( InterruptedException e ) { throw new WebDriverException ( e ) ; } } finally { asyncResult = null ; } }
Injects an asynchronous script for execution and waits for its result .