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:info.magnolia.integrationtests.uitest.AdmincentralUITest.java

License:Open Source License

@Test
public void sendAndRetrieveMessage() {
    // GIVEN//from  www. j  a v  a 2  s  .c  o m
    String messageContent = String.format("iam a message content %d", new Date().getTime());
    getCollapsibleAppSectionIcon("Dev").click();
    getAppIcon("Messages").click();
    waitUntil(appIsLoaded());
    assertAppOpen("Messages");

    // WHEN
    //getElements(By.xpath("//*[contains(@class, 'v-layout')]//input[@type = 'text' and contains(@class, 'v-textfield')]"), 2).get(0).sendKeys("iam a message");
    getElement(By.xpath(
            "//*[contains(@class, 'v-formlayout-firstrow')]//input[@type = 'text' and contains(@class, 'v-textfield')]"))
                    .sendKeys("iam a message");
    getElement(By.xpath("//textarea")).sendKeys(messageContent);
    getNativeButton("commit").click();
    closeInfoNotification();
    closeApp();
    getShellIconPulse().click();
    getPulseTab("Messages").click();

    // THEN
    delay(1, "make sure pulse table is updated");
    WebElement message = getElement(By.xpath(String.format("//*[text() = '%s']", messageContent)));
    assertTrue(message.isDisplayed());
}

From source file:info.magnolia.integrationtests.uitest.AdmincentralUITest.java

License:Open Source License

@Test
public void ensureClickingOnMoreInErrorNotificationOpensMessageDetail() {
    // GIVEN/*from ww w. j  a v  a  2s . c  om*/
    String messageContent = String.format("iam an error %d", new Date().getTime());
    String messageTitle = "iam an error";
    getCollapsibleAppSectionIcon("Dev").click();
    getAppIcon("Messages").click();
    waitUntil(appIsLoaded());
    assertAppOpen("Messages");

    // WHEN
    //getElements(By.xpath("//*[contains(@class, 'v-layout')]//input[@type = 'text' and contains(@class, 'v-textfield')]"), 2).get(0).sendKeys(messageTitle);
    getElement(By.xpath(
            "//*[contains(@class, 'v-formlayout-firstrow')]//input[@type = 'text' and contains(@class, 'v-textfield')]"))
                    .sendKeys(messageTitle);
    getElement(By.xpath("//textarea")).sendKeys(messageContent);
    getElement(By.xpath("//label[text() = 'Error']")).click();
    getNativeButton("commit").click();
    // Click on the MORE link
    getElement(By.className("link")).click();

    // THEN
    delay(2, "make sure pulse switch to message detail view");
    WebElement title = getElement(By.cssSelector(".v-pulse .message-title"));
    assertEquals(messageTitle, title.getText());
    WebElement actionbar = getElement(By.cssSelector(".v-actionbar"));
    assertTrue(actionbar.isDisplayed());
}

From source file:io.fabric8.selenium.forge.ProjectsPage.java

License:Apache License

public void goToProjectsPage() {
    WebDriverFacade facade = getFacade();

    facade.untilLinkClickedLoop(projectsLinkBy, buildConfigsUrl);

    facade.untilOneOf(signInBy, createProjectBy);

    WebElement signIn = facade.findOptionalElement(signInBy);
    if (signIn != null && signIn.isDisplayed()) {
        logInfo("Waiting for signin button to be clicked");
        facade.untilLinkClicked(signInBy);
        signIntoGogs();/*  w w w  .  ja v a  2  s. co  m*/
    } else {
        logInfo("Sign in button not present");
    }

    logWait("button: " + createProjectBy + "");
    facade.untilIsEnabled(createProjectBy);
}

From source file:io.fabric8.selenium.FormFacade.java

License:Apache License

public void submit() {
    getFacade().until("Form inputs: " + inputValues, new ExpectedCondition<Boolean>() {
        @Override//from w ww . j  a  v a2  s .com
        public Boolean apply(WebDriver driver) {
            logWait("" + inputValues + " on " + driver.getCurrentUrl());
            WebElement submitElement = null;
            for (InputValue inputValue : inputValues) {
                submitElement = inputValue.doInput();
                if (submitElement == null) {
                    logInfo("Missing " + inputValue + "");
                    return false;
                }
            }
            if (submitBy == null && submitElement == null) {
                fail("No input fields submitted yet");
                return false;
            } else {
                getFacade().sleep(Millis.seconds(5));
                if (submitBy != null) {
                    getFacade().untilIsEnabled(submitBy);
                    submitElement = getFacade().findOptionalElement(submitBy);
                    if (submitElement == null) {
                        logWarn("Could not find submit button " + submitBy + "");
                        return false;
                    } else {
                        if (!submitElement.isDisplayed() || !submitElement.isEnabled()) {
                            logWarn("Submit button " + submitBy + " not enabled and visible");
                            return false;
                        }
                        logInfo("Submitting form: " + inputValues + " on " + submitElement + "");
                        submitElement.click();
                    }
                } else {
                    logInfo("Submitting form: " + inputValues + " on " + submitElement + "");
                    submitElement.submit();
                }
                return true;
            }
        }
    });
}

From source file:io.fabric8.selenium.WebDriverFacade.java

License:Apache License

public boolean untilIsDisplayed(long timeoutInSeconds, final By firstBy, final By secondBy) {
    String message = "" + firstBy + " then  " + secondBy + " is displayed";
    return until(message, timeoutInSeconds, new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver driver) {
            WebElement element = findOptionalElement(firstBy);
            if (element == null) {
                logWait("" + firstBy + "");
                return false;
            } else {
                WebElement link = findOptionalElement(element, secondBy);
                if (link != null && link.isDisplayed()) {
                    logInfo("" + firstBy + " then " + secondBy + " displayed");
                    return true;
                } else {
                    logWait("" + firstBy + " then " + secondBy + " displayed");
                    return false;
                }//from   w ww. ja  v a2  s.  c o  m
            }
        }
    });
}

From source file:io.fabric8.selenium.WebDriverFacade.java

License:Apache License

public boolean untilIsDisplayed(long timeoutInSeconds, final By by) {
    return untilElementPredicate(timeoutInSeconds, by, new Function<WebElement, Boolean>() {
        @Override// w ww .j ava  2s  .  c om
        public String toString() {
            return "element.isDisplayed()";
        }

        @Override
        public Boolean apply(WebElement element) {
            return element.isDisplayed();
        }
    });
}

From source file:io.fabric8.selenium.WebDriverFacade.java

License:Apache License

/**
 * Waits until one of the given elements is available
 *///w  w w.ja va  2 s .co m
public void untilOneOf(final By... bys) {
    final List<By> byList = Arrays.asList(bys);
    String message = "One of these is available: " + byList;
    until(message, defaultTimeoutInSeconds, new ExpectedCondition<Boolean>() {

        @Override
        public Boolean apply(WebDriver driver) {
            for (By by : bys) {
                WebElement element = findOptionalElement(by);
                if (element != null && element.isDisplayed() && element.isEnabled()) {
                    logInfo("Found " + element + " for " + by + "");
                    return true;
                }
            }
            logInfo("Still not found any of " + byList + "");
            return false;
        }
    });
}

From source file:io.github.blindio.prospero.core.browserdrivers.WebDriverDriver.java

License:Apache License

public boolean isElementVisible(String locator) {
    try {// w w  w  . ja  v  a2  s .c  o m
        WebElement elem;
        elem = getWebDriver().findElement(BySeleneseLocator.seleneseLocator(locator));
        return elem.isDisplayed();
    } catch (NoSuchElementException nsee) {
        return false;
    }
}

From source file:io.github.seleniumquery.functions.jquery.events.ClickFunctionUtils.java

License:Apache License

public static String toString(WebElement element) {
    return "\n\t id attribute: \"" + element.getAttribute("id") + "\"" + "\n\t class attribute: \""
            + element.getAttribute("class") + "\"" + "\n\t name attribute: \"" + element.getAttribute("name")
            + "\"" + "\n\t tag: \"" + element.getTagName() + "\"" + "\n\t text: \"" + element.getText() + "\""
            + "\n\t value attribute: " + element.getAttribute("value") + "\"" + "\n\t size()/dimension: "
            + element.getSize() + "\n\t isDisplayed(): " + element.isDisplayed() + "\n\t isEnabled(): "
            + element.isEnabled() + "\n\t toString(): " + element + "\n";
}

From source file:io.github.seleniumquery.utils.SelectorUtils.java

License:Apache License

@SuppressWarnings("UnnecessaryLocalVariable")
public static boolean isVisible(WebElement element) {
    boolean elementIsNotVisible = !element.isDisplayed();
    if (elementIsNotVisible) {
        return false;
    }/*from  www.ja  v  a2  s .c om*/
    // at this point, it is visible!

    // And either we are not in HtmlUnitDriver
    if (!(element instanceof HtmlUnitWebElement)) {
        return true; // in that case, if the driver said it was visible, then it is
    }
    // ...or we are in HtmlUnitDriver.

    // #Cross-Driver
    // HtmlUnitDriver, says some elements are visible when they arent. So we must do some additional
    // checking to correct its result.

    // CHECKING #1: if JS is OFF, HtmlUnitDriver says everyone is visible, when that's not the case!
    // so we do some force-checking. If it finds the element is not visible, we return as so.
    if (!isHtmlUnitWebElementReallyDisplayed(element)) {
        return false;
    }

    // CHECKING #2: If all verification above passed, then we still think it is visible.
    // The last checking is seeing if the given element is under <body>:
    //         Firefox and Chrome don't consider elements directly under <html> (such as, commonly, <title>, <meta>, etc.,
    //      EXCEPT for <body>) to be visible, so we filter them, because HtmlUnitDriver thinks they ARE visible.
    boolean isBodyOrChildOfBody = !element.findElements(By.xpath("ancestor-or-self::body")).isEmpty();
    // in other words, it is visible only if it is <body> or if it has <body> as its parent
    return isBodyOrChildOfBody;
}