Java Code Examples for org.openqa.selenium.WebDriverException#getMessage()

The following examples show how to use org.openqa.selenium.WebDriverException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeleniumHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether exception indicates a 'stale element', not all drivers throw the exception one would expect...
 * @param e exception caught
 * @return true if exception indicated the element is no longer part of the page in the browser.
 */
public boolean isStaleElementException(WebDriverException e) {
    boolean result = false;
    if (e instanceof StaleElementReferenceException) {
        result = true;
    } else {
        String msg = e.getMessage();
        if (msg != null) {
            result = msg.contains("Element does not exist in cache") // Safari stale element
                    || msg.contains("unknown error: unhandled inspector error: {\"code\":-32000,\"message\":\"Cannot find context with specified id\"}") // chrome error
                    || msg.contains("Error: element is not attached to the page document") // Alternate Chrome stale element
                    || msg.contains("can't access dead object"); // Firefox stale element
        }
    }
    return result;
}
 
Example 2
Source File: JavascriptHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
/**
 * Executes Javascript in browser. If script contains the magic variable 'arguments'
 * the parameters will also be passed to the statement. In the latter case the parameters
 * must be a number, a boolean, a String, WebElement, or a List of any combination of the above.
 * @link http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/JavascriptExecutor.html#executeScript(java.lang.String,%20java.lang.Object...)
 * @param script javascript to run.
 * @param parameters parameters for the script.
 * @return return value from statement.
 */
public static Object executeScript(JavascriptExecutor jse, String script, Object... parameters) {
    Object result;
    try {
        result = jse.executeScript(script, parameters);
    } catch (WebDriverException e) {
        String msg = e.getMessage();
        if (msg != null && msg.contains("Detected a page unload event; script execution does not work across page loads.")) {
            // page reloaded while script ran, retry it once
            result = jse.executeScript(script, parameters);
        } else {
            throw e;
        }
    }
    return result;
}
 
Example 3
Source File: SeleneseCommand.java    From selenium with Apache License 2.0 6 votes vote down vote up
public T apply(WebDriver driver, String[] args) {
  try {
    switch (args.length) {
      case 0:
        return handleSeleneseCommand(driver, null, null);

      case 1:
        return handleSeleneseCommand(driver, args[0], null);

      case 2:
        return handleSeleneseCommand(driver, args[0], args[1]);

      default:
        throw new SeleniumException("Too many arguments! " + args.length);
    }
  } catch (WebDriverException e) {
    throw new SeleniumException(e.getMessage(), e);
  }
}
 
Example 4
Source File: SeleniumHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether exception indicates connection with webdriver is lost.
 * @param e exception caught
 * @return true if exception indicated we can no longer communicate with webdriver.
 */
public boolean exceptionIndicatesConnectionLost(WebDriverException e) {
    boolean result = e.getCause() instanceof SocketException;
    if (!result && e.getMessage() != null) {
        result = e.getMessage().contains("java.net.SocketException")
                || e.getMessage().contains("java.net.ConnectException");
    }
    return result;
}
 
Example 5
Source File: AppiumDriver.java    From java-client with Apache License 2.0 5 votes vote down vote up
@Override
public WebDriver context(String name) {
    checkNotNull(name, "Must supply a context name");
    try {
        execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name));
        return this;
    } catch (WebDriverException e) {
        throw new NoSuchContextException(e.getMessage(), e);
    }
}
 
Example 6
Source File: XpiDriverService.java    From selenium with Apache License 2.0 5 votes vote down vote up
/**
 * Configures and returns a new {@link XpiDriverService} using the default configuration. In
 * this configuration, the service will use the firefox executable identified by the
 * {@link FirefoxDriver.SystemProperty#BROWSER_BINARY} system property on a free port.
 *
 * @return A new XpiDriverService using the default configuration.
 */
public static XpiDriverService createDefaultService() {
  try {
    return new Builder().build();
  } catch (WebDriverException e) {
    throw new IllegalStateException(e.getMessage(), e.getCause());
  }
}
 
Example 7
Source File: MouseActions.java    From vividus with Apache License 2.0 4 votes vote down vote up
@Override
public ClickResult click(WebElement element, Optional<Action> defaultAlertAction)
{
    ClickResult clickResult = new ClickResult();
    if (element != null)
    {
        WebDriver webDriver = getWebDriver();
        WebElement page = webDriver.findElement(BODY_XPATH_LOCATOR);
        try
        {
            javascriptActions.scrollElementIntoViewportCenter(element);
            element.click();
            afterClick(clickResult, page, webDriver, defaultAlertAction);
        }
        catch (WebDriverException webDriverException)
        {
            String message = webDriverException.getMessage();
            if (message.contains("is not clickable at point"))
            {
                try
                {
                    if (webDriverManager.isTypeAnyOf(WebDriverType.CHROME)
                            && message.contains(". Other element would receive the click"))
                    {
                        javascriptActions.click(element);
                    }
                    else
                    {
                        element.click();
                    }
                    afterClick(clickResult, page, webDriver, defaultAlertAction);
                }
                catch (WebDriverException e)
                {
                    softAssert.recordFailedAssertion(COULD_NOT_CLICK_ERROR_MESSAGE + e);
                }
            }
            else if (message.contains("timeout: Timed out receiving message from renderer"))
            {
                softAssert.recordFailedAssertion(COULD_NOT_CLICK_ERROR_MESSAGE + webDriverException);
            }
            else if (message.contains("Timed out waiting for page to load"))
            {
                afterClick(clickResult, page, webDriver, defaultAlertAction);
            }
            else
            {
                throw webDriverException;
            }
        }
    }
    return clickResult;
}