Example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOf

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions visibilityOf

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui ExpectedConditions visibilityOf.

Prototype

public static ExpectedCondition<WebElement> visibilityOf(final WebElement element) 

Source Link

Document

An expectation for checking that an element, known to be present on the DOM of a page, is visible.

Usage

From source file:omelet.common.ExpectedConditionExtended.java

License:Apache License

/***
 * wait for the Element to be Disabled//www.  jav  a  2 s  . c  om
 * 
 * @param element
 * @return
 */
public static ExpectedCondition<Boolean> elementToBeDisabled(final WebElement element) {
    return new ExpectedCondition<Boolean>() {

        public ExpectedCondition<WebElement> visibilityOfElement = ExpectedConditions.visibilityOf(element);

        public Boolean apply(WebDriver driver) {
            boolean isDisabled = false;
            WebElement element = visibilityOfElement.apply(driver);
            try {
                if (element != null && !(element.isEnabled())) {
                    isDisabled = true;
                }
                return isDisabled;
            } catch (StaleElementReferenceException e) {
                // TODO check if error, debug or warn
                LOGGER.warn("Element not found: " + element.toString());
                return isDisabled;
            }
        }

        @Override
        public String toString() {
            return "element to be clickable: " + element;
        }
    };
}

From source file:org.alfresco.po.common.renderable.Renderable.java

License:Open Source License

/**
 * Wait for the annotated html elements on this renderable item
 *///from   ww w  . ja v a  2  s .c  om
private void waitFor() {
    for (Map.Entry<WrapsElement, WaitFor> entry : getWaitForHTMLElements().entrySet()) {
        WrapsElement element = entry.getKey();
        switch (entry.getValue().status()) {
        case VISIBLE: {
            webDriverWait().until(ExpectedConditions.visibilityOf(element.getWrappedElement()));
            break;
        }
        case HIDDEN: {
            webDriverWait().until(
                    ExpectedConditions.not(ExpectedConditions.visibilityOf(element.getWrappedElement())));
            break;
        }
        case CLICKABLE: {
            webDriverWait().until(ExpectedConditions.elementToBeClickable(element.getWrappedElement()));
            break;
        }
        }
    }
}

From source file:org.alfresco.po.common.util.Utils.java

License:Open Source License

/**
 * Helper method to wait for the visibility of an element
 */// www . j  a va 2s. co  m
public static void waitForVisibilityOf(WebElement webElement) {
    webDriverWait().until(ExpectedConditions.visibilityOf(webElement));
}

From source file:org.apache.archiva.web.test.parent.AbstractSeleniumTest.java

License:Apache License

public void submitLoginPage(String username, String password, boolean rememberMe, boolean validUsernamePassword,
        String assertReturnPage) {
    logger.info("Activating login form");
    // clickLinkWithLocator( "login-link-a", false);
    WebDriverWait wait = new WebDriverWait(getWebDriver(), 5);
    WebElement usernameField = wait.until(
            ExpectedConditions.visibilityOf(getWebDriver().findElement(By.id("user-login-form-username"))));
    wait = new WebDriverWait(getWebDriver(), 5);
    WebElement passwordField = wait.until(
            ExpectedConditions.visibilityOf(getWebDriver().findElement(By.id("user-login-form-password"))));
    wait = new WebDriverWait(getWebDriver(), 5);
    WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("modal-login-ok")));
    usernameField.sendKeys(username);//from  w  w w  .  j  a  va  2s .  c  o m
    passwordField.sendKeys(password);
    /*
    if ( rememberMe )
    {
    checkField( "rememberMe" );
    }*/

    button.click();
    if (validUsernamePassword) {
        assertUserLoggedIn(username);
    }
    /*
    else
    {
    if ( "Login Page".equals( assertReturnPage ) )
    {
        assertLoginPage();
    }
    else
    {
        assertPage( assertReturnPage );
    }
    }*/
}

From source file:org.apache.roller.selenium.AbstractRollerPage.java

License:Apache License

protected void verifyPageTitle(String waitForElementId, String pageTitle) {

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id(waitForElementId))));

    verifyPageTitle(pageTitle);//from ww  w.  j a va 2  s .c om
}

From source file:org.apache.roller.selenium.core.RegisterPage.java

License:Apache License

public WelcomePage submitUserRegistration() {
    clickById("submit");

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("a_clickHere"))));
    driver.findElement(By.id("a_clickHere")).click();

    return new WelcomePage(driver);
}

From source file:org.apache.tomcat.maven.webapp.test.SimpleTest.java

License:Apache License

@Test
public void testHelloWorld() throws InterruptedException {
    String serverUrl = System.getProperty("serverUrl");
    assertNotNull(serverUrl, "serverUrl was not found");

    WebDriver driver = new ChromeDriver();
    driver.get(serverUrl);//from  ww  w.  j  ava 2  s  . co  m
    //      driver.get("http://localhost:8080/");

    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("who"))));

    driver.findElement(By.id("who")).sendKeys("Hello World!");
    driver.findElement(By.id("send-btn")).click();

    wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("response"))));

    assertEquals("Unexpected response", "Hello Hello World!", driver.findElement(By.id("response")).getText());
    driver.quit();
}

From source file:org.awesomeagile.webapp.page.LandingPage.java

License:Apache License

public LandingPage loginWithGoogle(String endPoint) {
    driver.get(endPoint);//from  w  w  w  .  j  av a2s.  c o  m
    wait.until(ExpectedConditions.visibilityOf(loginButton));
    loginButton.click();
    wait.until(ExpectedConditions.visibilityOf(googleButton));
    googleButton.click();
    wait.until(ExpectedConditions.urlContains(endPoint));
    wait.until(ExpectedConditions.visibilityOf(userName));
    return this;
}

From source file:org.awesomeagile.webapp.page.LandingPage.java

License:Apache License

public LandingPage createDefinitionOfReady() {
    wait.until(ExpectedConditions.visibilityOf(createDefinitionOfReadyButton));
    createDefinitionOfReadyButton.click();
    wait.until(ExpectedConditions.visibilityOf(viewDefinitionOfReadyButton));
    return this;
}

From source file:org.awesomeagile.webapp.page.LandingPage.java

License:Apache License

public LandingPage createDefinitionOfDone() {
    wait.until(ExpectedConditions.visibilityOf(createDefinitionOfDoneButton));
    createDefinitionOfDoneButton.click();
    wait.until(ExpectedConditions.visibilityOf(viewDefinitionOfDoneButton));
    return this;
}