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.googlecode.fightinglayoutbugs.DetectElementsWithInvisibleFocus.java

License:Apache License

private FocusedElement toFocusedElement(@Nonnull WebElement activeElement, WebPage webPage) {
    // I don't trust WebDriver, that's why I determine the offset, width and height with jQuery too ...
    Map temp = new Gson()
            .fromJson(/* w  w  w.jav  a 2s . c  o m*/
                    (String) webPage.executeJavaScript(
                            "var $element = jQuery(arguments[0]);\n" + "var offset = $element.offset();\n"
                                    + "var $temp = $element.clone(false).wrap('<div></div>').parent();\n"
                                    + "try {\n" + "    return JSON.stringify({\n" + "        x: offset.left,\n"
                                    + "        y: offset.top,\n" + "        w: $element.width(),\n"
                                    + "        h: $element.height(),\n" + "        html: $temp.html()\n"
                                    + "    });\n" + "} finally {\n" + "    $temp.remove();\n" + "}",
                            activeElement),
                    Map.class);
    int x = ((Number) temp.get("x")).intValue();
    int y = ((Number) temp.get("y")).intValue();
    int w = ((Number) temp.get("w")).intValue();
    int h = ((Number) temp.get("h")).intValue();
    String html = (String) temp.get("html");
    if (activeElement.isDisplayed()) {
        Point location = activeElement.getLocation();
        Dimension size = activeElement.getSize();
        int x1 = Math.min(location.getX(), x);
        int y1 = Math.min(location.getY(), y);
        int x2 = Math.max(location.getX() + size.getWidth(), x + w) - 1;
        int y2 = Math.max(location.getY() + size.getHeight(), y + h) - 1;
        return new FocusedElement(activeElement, new RectangularRegion(x1, y1, x2, y2), html);
    } else {
        return new FocusedElement(activeElement, NOT_DISPLAYED, html);
    }
}

From source file:com.googlecode.fightinglayoutbugs.DetectInvalidImageUrls.java

License:Apache License

private void checkVisibleImgElements() {
    int numImgElementsWithoutSrcAttribute = 0;
    int numImgElementsWithEmptySrcAttribute = 0;
    final Set<String> seen = new HashSet<String>();
    for (WebElement img : _webPage.findElements(By.tagName("img"))) {
        if (img.isDisplayed()) {
            final String src = img.getAttribute("src");
            if (src == null) {
                ++numImgElementsWithoutSrcAttribute;
            } else if ("".equals(src)) {
                ++numImgElementsWithEmptySrcAttribute;
            } else {
                if (seen.add(src)) {
                    try {
                        checkImageUrl(src,
                                "Detected visible <img> element with invalid src attribute \"" + src + "\"");
                    } catch (MalformedURLException e) {
                        addLayoutBugIfNotPresent("Detected visible <img> element with invalid src attribute \""
                                + src + "\" -- " + e.getMessage());
                    }//ww w .j a  v  a  2s .c  o m
                }
            }
        }
    }
    if (numImgElementsWithEmptySrcAttribute > 0) {
        if (numImgElementsWithEmptySrcAttribute == 1) {
            addLayoutBugIfNotPresent("Detected visible <img> element with empty src attribute.");
        } else {
            addLayoutBugIfNotPresent("Detected " + numImgElementsWithEmptySrcAttribute
                    + " visible <img> elements with empty src attribute.");
        }
    }
    if (numImgElementsWithoutSrcAttribute > 0) {
        if (numImgElementsWithEmptySrcAttribute == 1) {
            addLayoutBugIfNotPresent("Detected visible <img> without src attribute.");
        } else {
            addLayoutBugIfNotPresent("Detected " + numImgElementsWithoutSrcAttribute
                    + " visible <img> elements without src attribute.");
        }
    }
}

From source file:com.hack23.cia.systemintegrationtest.UserPageVisit.java

License:Apache License

/**
 * Wait until displayed./*w ww  .  j av  a2  s  .  c o  m*/
 *
 * @param element
 *            the element
 */
private void waitUntilDisplayed(final WebElement element) {
    // Sleep until the div we want is visible or 5 seconds is over
    final long end = System.currentTimeMillis() + WAIT_FOR_PAGE_ELEMENT;
    while (System.currentTimeMillis() < end) {
        // If results have been returned, the results are displayed in a
        // drop
        if (element.isDisplayed() && element.isEnabled()) {
            break;
        }
    }
}

From source file:com.hotwire.selenium.bex.BexAbstractPage.java

License:Open Source License

/**
 * For handling tables especially with multiple tabs
 * @param rowCss - table row css selector with column specification i.e. "ul.accountRow li.column4"
 * @param rowText - text that should be matched
 *///  ww  w.ja va  2s  .co  m
protected void selectTableRow(String rowCss, String rowText) {
    List<WebElement> rows = findMany(rowCss);
    boolean notfound = true;
    for (WebElement row : rows) {
        if ((rowText.equals(row.getText())) && (row.isDisplayed())) {
            logger.info("Selecting row with value: " + rowText);
            notfound = false;
            row.click();
            break;
        }
    }
    if (notfound) {
        throw new NoSuchElementException("Row not found");
    }
}

From source file:com.hotwire.selenium.desktop.common.billing.HotelBillingPage.java

License:Open Source License

public HotelBillingPage setProvince(String province) {
    boolean availableElement = false;
    for (WebElement element : getWebDriver()
            .findElements(By.cssSelector("select[name='paymentInfoModel.newCreditCard.province']"))) {
        if (element.isDisplayed()) {
            Select select = new Select(element);
            // If province is a number, select by index. If not select by value of province.
            try {
                select.selectByIndex(Integer.parseInt(province));
                availableElement = true;
                break;
            } catch (NumberFormatException e) {
                select.selectByValue(province);
                availableElement = true;
                break;
            }/*from   ww w. ja  v a2s .  com*/
        }
        LOGGER.info("Select Province class: " + element.getAttribute("class") + " not displayed.");
    }
    if (!availableElement) {
        LOGGER.info("No selectable province elements visible for use.");
    }
    return this;
}

From source file:com.hotwire.selenium.desktop.common.billing.HotelBillingPage.java

License:Open Source License

public WebElement getProvince() {
    // This billing page has 3 province selectors that may or may not be visible. Can't just grab the first one
    // and expect it to be visible.
    for (WebElement element : getWebDriver()
            .findElements(By.cssSelector("select[name='paymentInfoModel.newCreditCard.province']"))) {
        if (element.isDisplayed()) {
            return element;
        }//from   www.  ja  v  a2  s  . c o  m
    }
    return null;
}

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

License:Open Source License

public boolean verifyMoreDetailsLinks() {

    // Iterate through all more details links and click them to see if ds
    // popup is invoked.
    for (WebElement element : moreDetails) {
        try {//from   ww  w  .  j a  v  a  2  s . c om
            if (element.isDisplayed()) {
                element.click();
                if (!dsPopUp.isDisplayed()) {
                    return false;
                } else {
                    //if ds popup is opened, close it.
                    new Wait<>(ExpectedConditions
                            .elementToBeClickable(By.xpath("//div[@class='yui-panel-container shadow']/div/a")))
                                    .maxWait(3).apply(getWebDriver()).click();
                }
            } else {
                return false;
            }
        } catch (NoSuchElementException e) {
            logger.info("Element - More details links and/or DS pop-up, don't appear.");
        }
    }

    return true;
}

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

License:Open Source License

public String getActiveTabText() {
    for (WebElement webElement : getWebDriver().findElements(By.cssSelector("div[role='tabpanel']"))) {
        if (webElement.isDisplayed()) {
            return webElement.getText();
        }//from  w  ww .  j  av a 2  s.co  m
    }
    throw new NoSuchElementException("Could not find active tab!");
}

From source file:com.hotwire.selenium.desktop.us.billing.car.impl.accordion.AcPaymentMethodFragment.java

License:Open Source License

public WebElement getPaymentState() {
    for (WebElement element : getWebDriver().findElements(By.cssSelector(container
            + " .countryFields .state select, " + container + " .countryFields .provinceCanada select, "
            + container + " .countryFields .provinceOther input"))) {
        LOGGER.info("PAYMENT STATE: " + element.getAttribute("id"));
        if (element.isDisplayed()) {
            return element;
        }/*from   ww w .  j ava 2 s.  c om*/
    }
    return null;
}

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

License:Open Source License

@Override
public CarTravelerInfo creditCardAcceptance(boolean accepted) {

    WebElement cb = getCardAcceptance();

    if (cb != null && cb.isDisplayed()) {
        if (accepted && !cb.isSelected()) {
            cb.click();//  w  ww . j a  v a2  s.  c  o m
        }

        if (!accepted && cb.isSelected()) {
            cb.click();
        }
    }
    return this;
}