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.hotwire.selenium.angular.AngularFareFinderFragment.java

License:Open Source License

/**
 * This chooses the first item from the dropdown that contains the destination string.
 *
 * @param destination//from ww w  .  j  a v  a2s  . c  o m
 */
private void selectDestinationFromDropdown(String destination) {
    try {
        new WebDriverWait(getWebDriver(), 3)
                .until(new VisibilityOf(By.cssSelector(".site-content ul.dropdown-menu")));
    } catch (TimeoutException e) {
        LOGGER.info("AutoComplete menu didn't show for " + destination + " destination.");
        return;
    }
    List<WebElement> locations = getWebDriver()
            .findElements(By.cssSelector(".site-content ul.dropdown-menu li a"));
    for (WebElement element : locations) {
        if (element.getText().trim().contains(destination)) {
            element.click();
            return;
        }
    }
    this.destination.sendKeys(Keys.ESCAPE);
}

From source file:com.hotwire.selenium.desktop.account.AccountPreferencesPage.java

License:Open Source License

public void addFavoriteAirport(String airportName) {
    // DO: Factor out clicking autocomplete in HotelSearchFragment to a generic place and
    // change the sendkeys below to use that method call when the autocomplete list for my
    // account is changed back to match in Prod/QA as QACI items do not save.
    favAirportInput.sendKeys(airportName + Keys.ESCAPE + Keys.TAB); // Do not choose from list.
    new WebDriverWait(getWebDriver(), DEFAULT_WAIT, SLEEP_INTERVAL_MILLIS)
            .until(PageObjectUtils.webElementVisibleTestFunction(autoCompleteContent, false));
    new WebDriverWait(getWebDriver(), DEFAULT_WAIT)
            .until(new IsElementLocationStable(getWebDriver(), By.xpath(SAVE_BUTTON)));
    saveChangesButton.click();/*from   ww  w .j ava2  s  .  c o  m*/
}

From source file:com.hotwire.selenium.desktop.row.search.AbstractFareFinder.java

License:Open Source License

@Override
public FareFinder setDestinationLocation(String destinationLocation) {
    location.setText(destinationLocation);
    try {/*from w  w  w  .  j  av  a  2  s .c  om*/
        WebElement autocomplete = new WebDriverWait(getWebDriver(), 5)
                .until(ExpectedConditions.visibilityOfElementLocated(
                        By.xpath("//input[@id='location']/..//div[@class='yui-ac-content']")));
        autocomplete.sendKeys(Keys.ESCAPE);
    } catch (TimeoutException e) {
        logger.info("Autocomplete failed to become visible... Continuing...");
    }
    return this;
}

From source file:com.hotwire.selenium.desktop.row.search.SemPageFareFinder.java

License:Open Source License

/**
 * This chooses the first item from the dropdown that contains the destination string.
 *
 * @param destination//from www.  j a v  a 2 s .  co  m
 */
private void selectDestinationFromDropdown(String destination) {
    try {
        new org.openqa.selenium.support.ui.WebDriverWait(getWebDriver(), 3)
                .until(new VisibilityOf(By.cssSelector(".site-content ul.dropdown-menu")));
    } catch (TimeoutException e) {
        LOGGER.info("AutoComplete menu didn't show for " + destination + " destination.");
        return;
    }
    List<WebElement> locations = getWebDriver()
            .findElements(By.cssSelector(".site-content ul.dropdown-menu li a"));
    for (WebElement element : locations) {
        if (element.getText().trim().contains(destination)) {
            element.click();
            return;
        }
    }
    this.destination.sendKeys(Keys.ESCAPE);
}

From source file:com.hotwire.selenium.desktop.us.search.AirSearchFragment.java

License:Open Source License

private void setRoutesInfo(String fromThisLocation, String toThisLocation, Date startDate, Date endDate) {
    fromLocation.clear();/*from  w w  w. j a va2 s . co m*/
    fromLocation.click();
    fromLocation.sendKeys(fromThisLocation);

    try {
        new WebDriverWait(getWebDriver(), DEFAULT_WAIT, SLEEP_INTERVAL_MILLIS)
                .until(PageObjectUtils.webElementVisibleTestFunction(
                        fareFinderForm.findElement(By.cssSelector(FARE_FINDER_AUTOCOMPLETE_CONTENT)), false));
    } catch (TimeoutException e) {
        LOGGER.info("Timed out waiting for autocomplete to vanish. Attempt to manually make it disappear.");
        fromLocation.sendKeys(Keys.ESCAPE);
    }
    LOGGER.info("Departure location is \"{}\"", fromThisLocation);

    toLocation.clear();
    toLocation.click();
    toLocation.sendKeys(toThisLocation);
    try {
        new WebDriverWait(getWebDriver(), DEFAULT_WAIT, SLEEP_INTERVAL_MILLIS)
                .until(PageObjectUtils.webElementVisibleTestFunction(
                        fareFinderForm.findElement(By.cssSelector(FARE_FINDER_AUTOCOMPLETE_CONTENT)), false));
    } catch (TimeoutException e) {
        LOGGER.info("Timed out waiting for autocomplete to vanish. Attempt to manually make it disappear.");
        toLocation.sendKeys(Keys.ESCAPE);
    }
    LOGGER.info("Arrived to \"{}\"", toThisLocation);

    selectStartDate(startDate);

    if (endDate != null && roundTripRadioButton.isEnabled()) {
        selectEndDate(endDate);
    }
}

From source file:com.hotwire.selenium.desktop.widget.DatePicker.java

License:Open Source License

public void typeDate(String formattedDateString) {
    logger.info("Typing date: " + formattedDateString);
    inputElement.click();/*  ww w .  j  a v  a 2  s  .  c o  m*/
    inputElement.clear();
    inputElement.sendKeys(formattedDateString + Keys.ESCAPE);

    new WebDriverWait(getWebDriver(), MAX_WAIT)
            .until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(CSS_CALENDAR)));
}

From source file:com.hotwire.selenium.mobile.search.HotelSearchFragment.java

License:Open Source License

private void typeLocationAndClickOnMatch(String destinationLocation, int subStringLength) {
    // Split up string to grab the first 3 characters as this is the first trigger to the
    // autocomplete menu showing up. Guard against IndexOutOfBoundsException.
    int substringLength = subStringLength;
    String startString = (destinationLocation.length() > substringLength)
            ? destinationLocation.substring(0, substringLength)
            : destinationLocation;//  ww  w.j a  v  a2s  .com
    // Get the start autocomplete list. This list is always visible. It initially contains "Current Location" item.
    List<WebElement> acList = getWebDriver().findElements(By.cssSelector(DESTINATION_LAYER_LOCATIONS_LIST));

    hotelLocation.click();
    hotelLocation.clear();
    hotelLocation.sendKeys(startString);
    try {
        waitForAutoCompleteListToChange(getWebDriver(), acList);
    } catch (TimeoutException e) {
        /* Do nothing. The user might type something that has no matches. */ }

    acList = getWebDriver().findElements(By.cssSelector(DESTINATION_LAYER_LOCATIONS_LIST));
    boolean matchFound = false;
    for (WebElement item : acList) {
        if (item.getText().trim().toLowerCase().equals(destinationLocation.trim().toLowerCase())) {
            logger.info("Exact location match for " + destinationLocation
                    + " found in location autocomplete. Clicking menu item.");
            matchFound = true;
            item.click();
            break;
        }
    }
    if (!matchFound) {
        for (WebElement item : acList) {
            if (item.getText().trim().toLowerCase().contains(destinationLocation.trim().toLowerCase())) {
                logger.info("Autocomplete menu item found that contains " + destinationLocation
                        + " as substring. Clicking menu item.");
                matchFound = true;
                item.click();
                break;
            }
        }
        if (!matchFound) {
            logger.info("NO exact or substring location match for " + destinationLocation
                    + ". Typing location manually.");
            for (int i = 0; i < substringLength; i++) {
                hotelLocation.sendKeys(Keys.BACK_SPACE);
            }
            hotelLocation.sendKeys(destinationLocation + Keys.ESCAPE);
            hotelLocation.submit();
        }
    }
}

From source file:com.ibm.watson.app.qaclassifier.selenium.MenuIT.java

License:Open Source License

@Test
public void closeMenuOverlayWithEscapeKey() {
    WebElement menuIconContainer = driver.findElement(By.id("menuIconContainerDesktop"));
    WebElement menuIconImg = menuIconContainer
            .findElement(By.xpath(".//span[contains(concat(' ', @class, ' '), ' menuIconImg ')]"));

    menuIconImg.click();//from w ww.  j  a v  a 2s .c om
    WebElement menuList = driver.findElement(By.className("menu-list"));
    List<WebElement> menuOptions = menuList.findElements(By.xpath(".//ul/li"));

    // The first item should be home, which is hidden on Desktop, so skip it and do the second one
    WebElement firstMenuOption = menuOptions.get(2);
    firstMenuOption.click();

    // Press ESC to close overlay
    WebElement menuOverlay = driver.findElement(By.id("menuOverlay"));
    menuOverlay.sendKeys(Keys.ESCAPE);
    assertTrue("Hitting the ESC key closes the menu overlay",
            driver.findElements(By.id("menuOverlay")).size() == 0);
}

From source file:com.opera.core.systems.MouseTest.java

License:Apache License

@After
public void afterEach() {
    // Tests sometimes cause problems because a context menu is opened on Desktop, ensure that we
    // cancel the context menu if any.
    new Actions(driver).sendKeys(Keys.ESCAPE).perform();
}

From source file:com.osbitools.ws.shared.xui.GenericGuiWebTest.java

License:LGPL

public void sendEscKey() {
    sendKey(Keys.ESCAPE);
}