@Override public Object executeScript(String script, Object... args) { if (!getCapabilities().isJavascriptEnabled()) { throw new UnsupportedOperationException( "You must be using an underlying instance of WebDriver that supports executing javascript"); } // Escape the quote marks script = script.replaceAll("\"", "\\\""); Iterable<Object> convertedArgs = Iterables.transform(Lists.newArrayList(args), new WebElementToJsonConverter()); Map<String, ?> params = ImmutableMap.of("script", script, "args", Lists.newArrayList(convertedArgs)); return execute(DriverCommand.EXECUTE_SCRIPT, params).getValue(); }
@Override public Object executeAsyncScript(String script, Object... args) { if (!getCapabilities().isJavascriptEnabled()) { throw new UnsupportedOperationException( "You must be using an underlying instance of " + "WebDriver that supports executing javascript"); } // Escape the quote marks script = script.replaceAll("\"", "\\\""); Iterable<Object> convertedArgs = Iterables.transform(Lists.newArrayList(args), new WebElementToJsonConverter()); Map<String, ?> params = ImmutableMap.of("script", script, "args", Lists.newArrayList(convertedArgs)); return execute(DriverCommand.EXECUTE_ASYNC_SCRIPT, params).getValue(); }
private Map<String, ?> validateScriptCommand(String script, Object... args) { if (!(isJavaScriptEnabled())) { throw new UnsupportedOperationException( "You must be using an underlying instance of WebDriver that supports executing javascript"); } script = script.replaceAll("\"", "\\\""); Iterable<?> convertedArgs = Iterables.transform(Lists.newArrayList(args), new WebElementToJsonConverter()); Map<String, ?> params = ImmutableMap.of("script", script, "args", Lists.newArrayList(convertedArgs)); return params; }