List of usage examples for org.openqa.selenium JavascriptExecutor executeAsyncScript
Object executeAsyncScript(String script, Object... args);
From source file:com.constellio.sdk.tests.selenium.adapters.base.WebDriverAdapter.java
License:Open Source License
@Override public Object executeAsyncScript(String script, Object... args) { JavascriptExecutor executor = (JavascriptExecutor) adapted; return executor.executeAsyncScript(script, convertScriptArguments(args)); }
From source file:com.qmetry.qaf.automation.ui.webdriver.QAFExtendedWebElement.java
License:Open Source License
@SuppressWarnings("unchecked") public <T> T executeAsyncScript(String js) { JavascriptExecutor executor = getWrappedDriver(); return (T) executor.executeAsyncScript("arguments[0]." + js, this); }
From source file:com.vilt.minium.impl.JQueryInvoker.java
License:Apache License
@SuppressWarnings("unchecked") public <T> T invoke(JavascriptExecutor wd, boolean async, String expression, Object... args) { try {/*from www .ja va 2 s .c o m*/ args = convertToValidArgs(args); Object[] fullArgs = args == null ? new Object[1] : new Object[args.length + 1]; fullArgs[0] = async; if (args != null) System.arraycopy(args, 0, fullArgs, 1, args.length); Object result = async ? wd.executeAsyncScript(lightInvokerScript(expression), fullArgs) : wd.executeScript(lightInvokerScript(expression), fullArgs); if (result instanceof Boolean && !((Boolean) result).booleanValue()) { fullArgs = args == null ? new Object[2] : new Object[args.length + 2]; fullArgs[0] = async; fullArgs[1] = styles; if (args != null) System.arraycopy(args, 0, fullArgs, 2, args.length); result = async ? wd.executeAsyncScript(fullInvokerScript(expression), fullArgs) : wd.executeScript(fullInvokerScript(expression), fullArgs); } if (!(result instanceof List)) throw new IllegalStateException(format("Expected a list with the result in the first position...")); List<?> resultAsList = (List<?>) result; // results can only be empty if it was a result of a jQuery evaluation if (resultAsList.isEmpty()) return (T) Collections.emptyList(); if (resultAsList.get(0) instanceof WebElement) { // it's an array of web elements return (T) resultAsList; } return (T) resultAsList.get(0); } catch (Exception e) { throw new WebElementsException(e); } }
From source file:minium.web.internal.drivers.DefaultJavascriptInvoker.java
License:Apache License
@SuppressWarnings("unchecked") protected <T> T doInvoke(JavascriptExecutor wd, boolean async, String expression, Object... args) { try {/*from www . j a v a 2s.co m*/ Object[] fullArgs = createLightInvokerScriptArgs(async, args); if (LOGGER.isTraceEnabled()) { LOGGER.trace("About to invoke light invoker:"); LOGGER.trace("async: {}", async); LOGGER.trace("expression: {}", expression); LOGGER.trace("fullArgs: {}", fullArgs); } Object result = async ? wd.executeAsyncScript(lightInvokerScript(expression), fullArgs) : wd.executeScript(lightInvokerScript(expression), fullArgs); LOGGER.trace("result: {}", result); List<?> response = getValidResponse(result); ResponseType type = ResponseType.of((String) response.get(0)); if (type == ResponseType.MINIUM_UNDEFINED) { // minium is not defined yet, we need to send all the necessary javascript fullArgs = createFullInvokerScriptArgs(async, args); if (LOGGER.isTraceEnabled()) { LOGGER.trace("About to invoke full invoker:"); LOGGER.trace("fullArgs: {}", fullArgs); } result = async ? wd.executeAsyncScript(fullInvokerScript(expression), fullArgs) : wd.executeScript(fullInvokerScript(expression), fullArgs); LOGGER.trace("result: {}", result); response = getValidResponse(result); type = ResponseType.of((String) response.get(0)); } return (T) extractValue(type, response); } catch (WebDriverException e) { throw new JavascriptInvocationFailedException(format("Failed invoking expression:\n", expression), e); } }