Example usage for org.openqa.selenium WebElement isDisplayed

List of usage examples for org.openqa.selenium WebElement isDisplayed

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement isDisplayed.

Prototype

boolean isDisplayed();

Source Link

Document

Is this element displayed or not?

Usage

From source file:com.hotwire.selenium.desktop.us.billing.car.impl.ccf.CcfDetailsFragment.java

License:Open Source License

@Override
public int getVendorMapNum() {
    List<WebElement> vendorMaps = getWebDriver().findElements(By.cssSelector(CSS_VENDOR_MAP));
    //Check how many maps displayed on vendor grid simultaneously
    //mapNum  - is number of displayed maps
    int mapNum = 0;
    for (WebElement vendorMap : vendorMaps) {
        if (vendorMap.isDisplayed()) {
            mapNum++;//from   w  w  w  .  j a v  a  2 s  .co m
        }
    }
    return mapNum;
}

From source file:com.hotwire.selenium.desktop.us.billing.onepage.HotelCreditCardFragment.java

License:Open Source License

public HotelCreditCardFragment withState(String state) {
    WebElement displayedElement = null;/*w  w  w. j  a  va  2  s  . c  o m*/
    for (WebElement item : this.state) {
        if (item.isDisplayed() && item.isEnabled()) {
            displayedElement = item;
            break;
        }
    }
    if (displayedElement == null) {
        return this;
    }

    ExtendedSelect select = new ExtendedSelect(displayedElement);
    try {
        select.selectByIndex(Integer.parseInt(state));
        return this;
    } catch (NumberFormatException e) {
        // Do nothing. State is non-numeric and continue.
    }
    if (displayedElement != null) {
        if (displayedElement.getTagName().equals("select")) {
            new ExtendedSelect(displayedElement).selectIfVisibleTextStartsWithText(state);
        } else {
            // Default to sendkeys. Most likely element is an input text
            // area.
            displayedElement.sendKeys(state);
        }
    }
    // Else do nothing as this page is doing country specific elements and
    // some countries
    // will not have this element.
    return this;
}

From source file:com.hotwire.selenium.desktop.us.billing.onepage.HotelCreditCardFragment.java

License:Open Source License

public HotelCreditCardFragment withSavedState(String state) {
    WebElement displayedElement = null;//from  ww  w. j  a v  a 2 s  .  co  m
    for (WebElement item : this.savedState) {
        if (item.isDisplayed()) {
            displayedElement = item;
            break;
        }
    }
    if (displayedElement == null) {
        return this;
    }
    ExtendedSelect select = new ExtendedSelect(displayedElement);
    try {
        select.selectByIndex(Integer.parseInt(state));
        return this;
    } catch (NumberFormatException e) {
        // Do nothing. State is non-numeric and continue.
    }
    if (displayedElement != null) {
        if (displayedElement.getTagName().equals("select")) {
            new ExtendedSelect(displayedElement).selectIfVisibleTextStartsWithText(state);
        } else {
            // Default to sendkeys. Most likely element is an input text
            // area.
            displayedElement.sendKeys(state);
        }
    }
    // Else do nothing as this page is doing country specific elements and
    // some countries
    // will not have this element.
    return this;
}

From source file:com.hotwire.selenium.desktop.us.discount.DiscountTripSummaryPanel.java

License:Open Source License

public Boolean hasDiscount() {
    boolean oldDisplayed = false;
    try {//from w  ww .  j a va2 s .c o m
        WebElement old = getWebDriver()
                .findElement(By.xpath("id('tripTotalTable')//*[@class='detail' and text()='Discount:']"));
        oldDisplayed = old.isDisplayed();
    } catch (NoSuchElementException e) {
        // Do nothing use initialized value.
    }
    boolean nextDisplayed = false;
    try {
        WebElement next = getWebDriver().findElement(By.cssSelector("#priceDetails .discountText, .discount"));
        nextDisplayed = next.isDisplayed();
    } catch (NoSuchElementException e) {
        // Do nothing use initialized value.
    }
    logger.info("Discount Displayed for OLD billing: " + oldDisplayed
            + ". Discount Displayed for NEW Details-Billing: " + nextDisplayed);
    return oldDisplayed || nextDisplayed;
}

From source file:com.hotwire.selenium.desktop.us.results.AirResultsPage.java

License:Open Source License

public void getFlightAbovePrice(double expectedPrice) {
    boolean flightFound = false;
    boolean istooLowToShowDisplayed;

    int centinel = 0;
    //Declare the element we are looking for
    try {//  w  w w  . j av a 2 s.c  o m
        WebElement tooLowToShow = getWebDriver().findElement(By.xpath("//img[@alt='TOO LOW TO SHOW']"));
        istooLowToShowDisplayed = tooLowToShow.isDisplayed();
    } catch (NoSuchElementException e) {
        istooLowToShowDisplayed = false;
    }

    //Print boolean to standard out
    System.out.println("Too Low to show : " + istooLowToShowDisplayed);
    if (istooLowToShowDisplayed) {
        centinel = 1;
    }
    for (int i = centinel; i < priceLookups.size(); i++) {
        String textPrice = priceLookups.get(i).findElement(By.cssSelector(".dollars")).getText().trim() + "."
                + priceLookups.get(i).findElement(By.cssSelector(".cents")).getText().trim();

        String subString = textPrice.substring(1);
        Double price = Double.parseDouble(subString);

        if (price >= expectedPrice) {
            priceLookups.get(i).click();
            flightFound = true;
            break;
        }
    }
    if (flightFound) {
        System.out.println("Flight has been selected");
    } else {
        throw new RuntimeException("No flights meeting criteria were found");
    }
}

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public boolean isTripWatcherLayerFromSpeedBump() {
    for (WebElement element : getWebDriver().findElements(By.cssSelector(TRIP_WATCHER_LAYER))) {
        if (element.isDisplayed()) {
            if (element.getAttribute("id").equals("speedBumpTripWatcherLayer-layer")) {
                return true;
            }//from   w w  w  .  j  av  a 2  s  . c  o m
        }
    }
    return false;
}

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public WebElement getVisibleTripWatcherSubscribeButton() {
    for (WebElement element : getWebDriver().findElements(By.cssSelector(SUBSCRIBE))) {
        if (element.isDisplayed()) {
            logger.info("Visible button element id: " + element.getAttribute("class"));
            return element;
        }/* www  .  j a v  a2 s .co  m*/
    }
    throw new RuntimeException("TripWatcher email not visible for use.");
}

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public WebElement getVisibleTripWatcherEmailElement() {
    for (WebElement element : getWebDriver().findElements(By.cssSelector(EMAIL))) {
        if (element.isDisplayed()) {
            logger.info("Visible email element id: " + element.getAttribute("id"));
            return element;
        }/*from  w ww. ja v  a 2 s.  co m*/
    }
    throw new RuntimeException("TripWatcher email not visible for use.");
}

From source file:com.hotwire.selenium.desktop.us.results.hotel.fragments.tripwatcher.HotelResultsTripwatcherLayerFragment.java

License:Open Source License

public static void waitForTripWatcherVisibility(final WebDriver webdriver) {
    new WebDriverWait(webdriver, 20).until(new ExpectedCondition<Boolean>() {
        @Override//from w  w w  .  ja  v a  2  s .c  o  m
        public Boolean apply(WebDriver input) {
            new HotelResultsPage(input);
            for (WebElement element : input.findElements(By.cssSelector(TRIP_WATCHER_LAYER))) {
                if (element.isDisplayed()) {
                    return true;
                }
            }
            return false;
        }
    });
}

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

License:Open Source License

public boolean checkCompareWithCheckboxState(String partnerName, String state) {

    try {//from   www . j  a  va  2s  .c o m
        WebElement cb = getCompareWithCheckboxByPartnerName(partnerName);
        if (cb.isDisplayed() && !"hidden".equals(state)) {
            if ("checked".equals(state) && cb.isSelected()) {
                return true;
            }
            if ("unchecked".equals(state) && !cb.isSelected()) {
                return true;
            }
        }
    } catch (NoSuchElementException exception) {
        if ("hidden".equals(state)) {
            return true;
        }
    }
    return false;
}