Example usage for org.openqa.selenium Keys ESCAPE

List of usage examples for org.openqa.selenium Keys ESCAPE

Introduction

In this page you can find the example usage for org.openqa.selenium Keys ESCAPE.

Prototype

Keys ESCAPE

To view the source code for org.openqa.selenium Keys ESCAPE.

Click Source Link

Usage

From source file:com.screenslicer.core.service.HttpStatus.java

License:Open Source License

public static int status(RemoteWebDriver driver, boolean wait) {
    if (WebApp.DEBUG) {
        System.out.println("check status...");
    }/*from w  w  w. j  av a2 s .co  m*/
    int totalWait = 0;
    String src = null;
    while (totalWait < TIMEOUT) {
        src = null;
        try {
            src = driver.getPageSource();
            if (!CommonUtil.isEmpty(src)) {
                synchronized (lock) {
                    prevLen = len;
                    len = src.length();
                }
            }
        } catch (Throwable t) {
            synchronized (lock) {
                src = null;
                prevLen = 0;
                len = 0;
            }
            Log.exception(t);
        }
        if (WebApp.DEBUG) {
            synchronized (lock) {
                System.out.println("status=" + status);
            }
        }
        synchronized (lock) {
            if (status != 0) {
                break;
            }
        }
        boolean validLen;
        synchronized (lock) {
            validLen = prevLen == len && len > MIN_LEN;
        }
        if (validLen && hasContent(null, src)) {
            try {
                driver.getKeyboard().sendKeys(Keys.ESCAPE);
            } catch (Throwable t) {
                Log.exception(t);
            }
            Util.driverSleepVeryShort();
            if (!hasContent(driver, src)) {
                synchronized (lock) {
                    status = 204;
                }
            }
            break;
        }
        if (wait) {
            if (WebApp.DEBUG) {
                System.out.println("waiting for status...");
            }
            try {
                Thread.sleep(SLEEP);
            } catch (InterruptedException e) {
                Log.exception(e);
            }
            totalWait += SLEEP;
        } else {
            break;
        }
    }
    int myStatus;
    synchronized (lock) {
        myStatus = status;
        status = -1;
    }
    return myStatus;
}

From source file:com.screenslicer.core.util.Util.java

License:Open Source License

public static void get(RemoteWebDriver driver, String url, Node urlNode, boolean retry) throws ActionFailed {
    boolean exception = true;
    boolean success = true;
    String origHandle = null;//from w  ww . j  ava 2  s. c o  m
    try {
        String source = null;
        boolean badUrl = true;
        boolean statusFail = true;
        if (urlNode != null) {
            origHandle = driver.getWindowHandle();
        }
        for (int i = 0; i < REFRESH_TRIES
                && (badUrl || statusFail || exception || CommonUtil.isEmpty(source)); i++) {
            badUrl = false;
            statusFail = false;
            exception = false;
            source = null;
            if (WebApp.DEBUG) {
                System.out.println("getting url...");
            }
            try {
                driver.getKeyboard().sendKeys(Keys.ESCAPE);
            } catch (Throwable t) {
                Log.exception(t);
            }
            if (urlNode != null) {
                try {
                    cleanUpNewWindows(driver, origHandle);
                } catch (Throwable t) {
                    Log.exception(t);
                }
            }
            try {
                Util.driverSleepVeryShort();
                if (urlNode != null) {
                    try {
                        Util.clickToNewWindow(driver, toElement(driver, urlNode));
                        Set<String> newHandles = driver.getWindowHandles();
                        for (String newHandle : newHandles) {
                            if (!origHandle.equals(newHandle)) {
                                driver.switchTo().window(newHandle);
                                break;
                            }
                        }
                    } catch (Throwable t) {
                        exception = true;
                        Log.exception(t);
                        Util.cleanUpNewWindows(driver, origHandle);
                    }
                } else {
                    driver.get("about:blank");
                    try {
                        driver.get(url);
                    } catch (TimeoutException e) {
                        Log.exception(e);
                    }
                }
                if (!exception) {
                    Util.driverSleepShort();
                    Util.driverSleepLong();
                    statusFail = HttpStatus.status(driver, urlNode != null) != 200;
                    driver.switchTo().defaultContent();
                    source = driver.getPageSource();
                    try {
                        new URL(driver.getCurrentUrl());
                        badUrl = false;
                    } catch (Throwable t) {
                        badUrl = true;
                    }
                }
            } catch (Throwable t) {
                Log.exception(t);
                exception = true;
            }
            if ((!retry || i + 1 == REFRESH_TRIES)
                    && (badUrl || statusFail || exception || CommonUtil.isEmpty(source))) {
                try {
                    driver.getKeyboard().sendKeys(Keys.ESCAPE);
                    Util.driverSleepVeryShort();
                } catch (Throwable t) {
                    Log.exception(t);
                }
                success = false;
                if (!retry) {
                    break;
                }
            }
        }
        if (WebApp.DEBUG) {
            System.out.println("getting url - done");
        }
    } catch (Throwable t) {
        Log.exception(t);
        success = false;
    }
    if (!success) {
        if (urlNode != null && origHandle != null) {
            try {
                cleanUpNewWindows(driver, origHandle);
            } catch (Throwable t) {
                Log.exception(t);
            }
        }
        throw new ActionFailed();
    }
}

From source file:com.seleniumtests.uipage.htmlelements.SelectList.java

License:Apache License

private void finalizeAction() {
    if (selectType == Type.ANGULAR_MATERIAL) {
        HtmlElement selectContent = new HtmlElement("options", By.className("mat-select-content"),
                frameElement);/*w ww  .  j  av  a2  s .  co  m*/
        if (selectContent.isElementPresent()) {
            element.sendKeys(Keys.ESCAPE);
        }
    }
}

From source file:com.thoughtworks.selenium.webdriven.commands.SendKeys.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    alertOverride.replaceAlertMethod(driver);

    value = value.replace("${KEY_ALT}", Keys.ALT);
    value = value.replace("${KEY_CONTROL}", Keys.CONTROL);
    value = value.replace("${KEY_CTRL}", Keys.CONTROL);
    value = value.replace("${KEY_META}", Keys.META);
    value = value.replace("${KEY_COMMAND}", Keys.COMMAND);
    value = value.replace("${KEY_SHIFT}", Keys.SHIFT);

    value = value.replace("${KEY_BACKSPACE}", Keys.BACK_SPACE);
    value = value.replace("${KEY_BKSP}", Keys.BACK_SPACE);
    value = value.replace("${KEY_DELETE}", Keys.DELETE);
    value = value.replace("${KEY_DEL}", Keys.DELETE);
    value = value.replace("${KEY_ENTER}", Keys.ENTER);
    value = value.replace("${KEY_EQUALS}", Keys.EQUALS);
    value = value.replace("${KEY_ESCAPE}", Keys.ESCAPE);
    value = value.replace("${KEY_ESC}", Keys.ESCAPE);
    value = value.replace("${KEY_INSERT}", Keys.INSERT);
    value = value.replace("${KEY_INS}", Keys.INSERT);
    value = value.replace("${KEY_PAUSE}", Keys.PAUSE);
    value = value.replace("${KEY_SEMICOLON}", Keys.SEMICOLON);
    value = value.replace("${KEY_SPACE}", Keys.SPACE);
    value = value.replace("${KEY_TAB}", Keys.TAB);

    value = value.replace("${KEY_LEFT}", Keys.LEFT);
    value = value.replace("${KEY_UP}", Keys.UP);
    value = value.replace("${KEY_RIGHT}", Keys.RIGHT);
    value = value.replace("${KEY_DOWN}", Keys.DOWN);
    value = value.replace("${KEY_PAGE_UP}", Keys.PAGE_UP);
    value = value.replace("${KEY_PGUP}", Keys.PAGE_UP);
    value = value.replace("${KEY_PAGE_DOWN}", Keys.PAGE_DOWN);
    value = value.replace("${KEY_PGDN}", Keys.PAGE_DOWN);
    value = value.replace("${KEY_END}", Keys.END);
    value = value.replace("${KEY_HOME}", Keys.HOME);

    value = value.replace("${KEY_NUMPAD0}", Keys.NUMPAD0);
    value = value.replace("${KEY_N0}", Keys.NUMPAD0);
    value = value.replace("${KEY_NUMPAD1}", Keys.NUMPAD1);
    value = value.replace("${KEY_N1}", Keys.NUMPAD1);
    value = value.replace("${KEY_NUMPAD2}", Keys.NUMPAD2);
    value = value.replace("${KEY_N2}", Keys.NUMPAD2);
    value = value.replace("${KEY_NUMPAD3}", Keys.NUMPAD3);
    value = value.replace("${KEY_N3}", Keys.NUMPAD3);
    value = value.replace("${KEY_NUMPAD4}", Keys.NUMPAD4);
    value = value.replace("${KEY_N4}", Keys.NUMPAD4);
    value = value.replace("${KEY_NUMPAD5}", Keys.NUMPAD5);
    value = value.replace("${KEY_N5}", Keys.NUMPAD5);
    value = value.replace("${KEY_NUMPAD6}", Keys.NUMPAD6);
    value = value.replace("${KEY_N6}", Keys.NUMPAD6);
    value = value.replace("${KEY_NUMPAD7}", Keys.NUMPAD7);
    value = value.replace("${KEY_N7}", Keys.NUMPAD7);
    value = value.replace("${KEY_NUMPAD8}", Keys.NUMPAD8);
    value = value.replace("${KEY_N8}", Keys.NUMPAD8);
    value = value.replace("${KEY_NUMPAD9}", Keys.NUMPAD9);
    value = value.replace("${KEY_N9}", Keys.NUMPAD9);
    value = value.replace("${KEY_ADD}", Keys.ADD);
    value = value.replace("${KEY_NUM_PLUS}", Keys.ADD);
    value = value.replace("${KEY_DECIMAL}", Keys.DECIMAL);
    value = value.replace("${KEY_NUM_PERIOD}", Keys.DECIMAL);
    value = value.replace("${KEY_DIVIDE}", Keys.DIVIDE);
    value = value.replace("${KEY_NUM_DIVISION}", Keys.DIVIDE);
    value = value.replace("${KEY_MULTIPLY}", Keys.MULTIPLY);
    value = value.replace("${KEY_NUM_MULTIPLY}", Keys.MULTIPLY);
    value = value.replace("${KEY_SEPARATOR}", Keys.SEPARATOR);
    value = value.replace("${KEY_SEP}", Keys.SEPARATOR);
    value = value.replace("${KEY_SUBTRACT}", Keys.SUBTRACT);
    value = value.replace("${KEY_NUM_MINUS}", Keys.SUBTRACT);

    value = value.replace("${KEY_F1}", Keys.F1);
    value = value.replace("${KEY_F2}", Keys.F2);
    value = value.replace("${KEY_F3}", Keys.F3);
    value = value.replace("${KEY_F4}", Keys.F4);
    value = value.replace("${KEY_F5}", Keys.F5);
    value = value.replace("${KEY_F6}", Keys.F6);
    value = value.replace("${KEY_F7}", Keys.F7);
    value = value.replace("${KEY_F8}", Keys.F8);
    value = value.replace("${KEY_F9}", Keys.F9);
    value = value.replace("${KEY_F10}", Keys.F10);
    value = value.replace("${KEY_F11}", Keys.F11);
    value = value.replace("${KEY_F12}", Keys.F12);

    finder.findElement(driver, locator).sendKeys(value);

    return null;/*  w ww  .j a  va 2s  .c o  m*/
}

From source file:com.thoughtworks.selenium.webdriven.commands.TypeKeys.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    alertOverride.replaceAlertMethod(driver);

    value = value.replace("\\10", Keys.ENTER);
    value = value.replace("\\13", Keys.RETURN);
    value = value.replace("\\27", Keys.ESCAPE);
    value = value.replace("\\38", Keys.ARROW_UP);
    value = value.replace("\\40", Keys.ARROW_DOWN);
    value = value.replace("\\37", Keys.ARROW_LEFT);
    value = value.replace("\\39", Keys.ARROW_RIGHT);

    finder.findElement(driver, locator).sendKeys(value);

    return null;/*from   w w w  .  jav a  2s .  c  om*/
}

From source file:com.thoughtworks.selenium.webdriven.commands.TypeKeysTest.java

License:Apache License

@Test
public void substitutesReturnAndEscapeKeys() {
    String expected = newString(Keys.ENTER, Keys.RETURN, Keys.ESCAPE);
    String input = "\\10\\13\\27";

    new TypeKeys(new AlertOverrideStub(), elementFinder).apply(null, new String[] { "foo", input });

    verify(element).sendKeys(expected);/*  w w w.j  a v a 2 s .c  om*/
}

From source file:com.vaadin.tests.components.grid.basicfeatures.client.GridEditorClientTest.java

License:Apache License

@Test
public void testKeyboardOpeningClosing() {

    getGridElement().getCell(4, 0).click();

    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();

    assertNotNull(getEditor());//w ww .  j  ava  2  s .c om

    new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();
    assertNull(getEditor());
    assertEquals("Row 4 edit cancelled", findElement(By.className("grid-editor-log")).getText());

    // Disable editor
    selectMenuPath("Component", "Editor", "Enabled");

    getGridElement().getCell(5, 0).click();
    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
    assertNull(getEditor());
}

From source file:com.vaadin.tests.components.grid.basicfeatures.server.GridEditorTest.java

License:Apache License

@Test
public void testKeyboardOpeningClosing() {

    getGridElement().getCell(4, 0).click();
    assertEditorClosed();//from   w  ww .j  a  v  a  2s. c om

    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
    assertEditorOpen();

    new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();
    assertEditorClosed();

    // Disable Editor
    selectMenuPath(TOGGLE_EDIT_ENABLED);
    getGridElement().getCell(5, 0).click();
    new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
    assertEditorClosed();
}

From source file:com.vaadin.tests.components.window.CloseShortcutTest.java

License:Apache License

private void attemptDefaultShortcut() {
    window.focus();
    $(TextFieldElement.class).first().sendKeys(Keys.ESCAPE);
}

From source file:com.vaadin.v7.tests.components.grid.GridEditorUITest.java

License:Apache License

@Test
public void testEditor() {
    assertFalse("Sanity check", isElementPresent(PasswordFieldElement.class));

    openEditor(5);//from w w w  .  j  av  a  2s  . co m
    new Actions(getDriver()).sendKeys(Keys.ESCAPE).perform();

    openEditor(10);

    assertTrue("Editor should be opened with a password field", isElementPresent(PasswordFieldElement.class));

    assertFalse("Notification was present", isElementPresent(NotificationElement.class));
}