org.openqa.selenium.JavascriptException Java Examples

The following examples show how to use org.openqa.selenium.JavascriptException. 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: RichFacesTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
protected void waitForJsfAjaxImpl(boolean checkLocation) {
    try {
        // if jsf is present on page, add an event listener that will be triggered when next Ajax request completes
        if (checkLocation) {
            waitForJavascriptCallback("if(!window.jsf||window.location.href!==arguments[0]){callback();}else{jsf.ajax.addOnEvent(function(data){if(data.status=='success')callback();});}",
                    previousLocation);
        } else {
            waitForJavascriptCallback("if(!window.jsf){callback();}else{jsf.ajax.addOnEvent(function(data){if(data.status=='success')callback();});}");
        }
    } catch (JavascriptException e) {
        String msg = e.getMessage();
        if (msg.startsWith("javascript error: document unloaded while waiting for result")) {
            // document is reloaded, no problem
        } else {
            throw e;
        }
    } finally {
        setShouldWaitForAjax(false);
    }
}
 
Example #2
Source File: Shadow.java    From shadow-automation-selenium with Apache License 2.0 5 votes vote down vote up
private boolean isPresent(WebElement element) {
	boolean present = false;
	try {
		present =  (Boolean) executerGetObject("return isVisible(arguments[0]);", element);
	} catch(JavascriptException ex) {
		
	}
	return present;
}
 
Example #3
Source File: ErrorHandlerTest.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Test
public void testStatusCodesRaisedBackToStatusMatches() {
  Map<Integer, Class<?>> exceptions = new HashMap<>();
  exceptions.put(ErrorCodes.NO_SUCH_SESSION, NoSuchSessionException.class);
  exceptions.put(ErrorCodes.NO_SUCH_ELEMENT, NoSuchElementException.class);
  exceptions.put(ErrorCodes.NO_SUCH_FRAME, NoSuchFrameException.class);
  exceptions.put(ErrorCodes.UNKNOWN_COMMAND, UnsupportedCommandException.class);
  exceptions.put(ErrorCodes.STALE_ELEMENT_REFERENCE, StaleElementReferenceException.class);
  exceptions.put(ErrorCodes.ELEMENT_NOT_VISIBLE, ElementNotVisibleException.class);
  exceptions.put(ErrorCodes.INVALID_ELEMENT_STATE, InvalidElementStateException.class);
  exceptions.put(ErrorCodes.UNHANDLED_ERROR, WebDriverException.class);
  exceptions.put(ErrorCodes.ELEMENT_NOT_SELECTABLE, ElementNotSelectableException.class);
  exceptions.put(ErrorCodes.JAVASCRIPT_ERROR, JavascriptException.class);
  exceptions.put(ErrorCodes.XPATH_LOOKUP_ERROR, InvalidSelectorException.class);
  exceptions.put(ErrorCodes.TIMEOUT, TimeoutException.class);
  exceptions.put(ErrorCodes.NO_SUCH_WINDOW, NoSuchWindowException.class);
  exceptions.put(ErrorCodes.INVALID_COOKIE_DOMAIN, InvalidCookieDomainException.class);
  exceptions.put(ErrorCodes.UNABLE_TO_SET_COOKIE, UnableToSetCookieException.class);
  exceptions.put(ErrorCodes.UNEXPECTED_ALERT_PRESENT, UnhandledAlertException.class);
  exceptions.put(ErrorCodes.NO_ALERT_PRESENT, NoAlertPresentException.class);
  exceptions.put(ErrorCodes.ASYNC_SCRIPT_TIMEOUT, ScriptTimeoutException.class);
  exceptions.put(ErrorCodes.INVALID_ELEMENT_COORDINATES, InvalidCoordinatesException.class);
  exceptions.put(ErrorCodes.IME_NOT_AVAILABLE, ImeNotAvailableException.class);
  exceptions.put(ErrorCodes.IME_ENGINE_ACTIVATION_FAILED, ImeActivationFailedException.class);
  exceptions.put(ErrorCodes.INVALID_SELECTOR_ERROR, InvalidSelectorException.class);
  exceptions.put(ErrorCodes.SESSION_NOT_CREATED, SessionNotCreatedException.class);
  exceptions.put(ErrorCodes.MOVE_TARGET_OUT_OF_BOUNDS, MoveTargetOutOfBoundsException.class);
  exceptions.put(ErrorCodes.INVALID_XPATH_SELECTOR, InvalidSelectorException.class);
  exceptions.put(ErrorCodes.INVALID_XPATH_SELECTOR_RETURN_TYPER, InvalidSelectorException.class);

  for (Map.Entry<Integer, Class<?>> exception : exceptions.entrySet()) {
    assertThatExceptionOfType(WebDriverException.class)
        .isThrownBy(() -> handler.throwIfResponseFailed(createResponse(exception.getKey()), 123))
        .satisfies(e -> {
          assertThat(e.getClass().getSimpleName()).isEqualTo(exception.getValue().getSimpleName());

          // all of the special invalid selector exceptions are just mapped to the generic invalid selector
          int expected = e instanceof InvalidSelectorException
                         ? ErrorCodes.INVALID_SELECTOR_ERROR : exception.getKey();
          assertThat(new ErrorCodes().toStatusCode(e)).isEqualTo(expected);
        });
  }
}