Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

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

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:barChart1.BarChartDemo.java

License:Open Source License

/**
 * Starting point for the demonstration application.
 *
 * @param args  ignored.//from   w  w  w . j a va 2s. c o  m
 */
public static void main(String[] args) {

    // Demo to buy tickets to the EK 2016

    System.out.println("Hello UEFA 2016 !!!");

    statistics = "";

    JOptionPane.showMessageDialog(null, "Belgium versus Italy demo start");

    driver = new FirefoxDriver();
    wait = new WebDriverWait(driver, 500);

    //Open Home Page
    driver.manage().window().maximize();
    driver.get("http://www.uefa.com/");

    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//div/header/nav/div/div/ul/li/a[text() = 'UEFA EURO 2016']")));

    driver.findElement(By.xpath("//div/header/nav/div/div/ul/li/a[text() = 'UEFA EURO 2016']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//nav/div/div/ul/li/a[ text() = 'Teams']")));

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//nav/div/div/ul/li/a[ text() = 'Matches']")))
            .click();

    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//div/div//div//div/a[text() = 'Select your team and follow their EURO journey']")));

    driver.findElement(
            By.xpath("//div/div//div//div/a[text() = 'Select your team and follow their EURO journey']"))
            .click();

    wait2Secs();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div//ul/li/span[text()='Belgium']")));

    driver.findElement(By.xpath("//div/div/div//ul/li/span[text()='Belgium']")).click();

    // Belgium
    wait2Secs();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("(//div/table[1]/tbody/tr/td/div/a[text()='21.00'])[1]")));

    driver.findElement(By.xpath("(//div/table[1]/tbody/tr/td/div/a[text()='21.00'])[1]")).click();

    wait2Secs();

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a/span[text()='Pre-match']")));

    // Go to the statistics

    driver.get("http://www.uefa.com/uefaeuro/season=2016/statistics/index.html");

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a/span[text()='Teams']")));

    driver.findElement(By.xpath("//a/span[text()='Teams']")).click();

    // Look up the statistics for Belgium and Italy

    getOverviewStats("BE", "ITA", "Belgium", "Italy");

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Goals']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Goals']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Belgium");
    ;

    wait2Secs();

    // getGoalsStats("BE","ITA","Belgium","Italy");

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Belgium");
    ;

    wait2Secs();

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Passes']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Passes']")).click();

    wait2Secs();

    // Italy

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Overview']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Overview']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Goals']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Goals']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Attempts']")).click();

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/ul/li/a[text()='Passes']")));

    driver.findElement(By.xpath("//div/div/div/ul/li/a[text()='Passes']")).click();

    wait.until(ExpectedConditions
            .visibilityOfElementLocated(By.xpath("//div/div/div/div/input[@value='Search for a team']")));

    driver.findElement(By.xpath("//div/div/div/div/input[@value='Search for a team']")).sendKeys("Italy");
    ;

    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

    JOptionPane.showMessageDialog(null, "Belgium versus Italy : \n" + statistics);

    BarChartDemo demo = new BarChartDemo("Belgium vs Italy");
    demo.pack();
    RefineryUtilities.centerFrameOnScreen(demo);
    demo.setVisible(true);

}

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

protected void waitUntilVisibilityOf(WebElement element) {
    new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOf(element));
}

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

protected void waitUntilVisibilityOf(By byId) {
    new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOf(driver.findElement(byId)));
}

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

protected void presenceOfElementLocated(By byId) {
    new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(byId));
}

From source file:be.rubus.web.testing.AbstractWidget.java

License:Apache License

protected void waitUntilHiddenOf(WebElement checkElement) {
    new WebDriverWait(driver, 5).until(ExpectedConditions.not(ExpectedConditions.visibilityOf(checkElement)));

}

From source file:be.rubus.web.testing.widget.AlertHandling.java

License:Apache License

public AlertHandling checkForAlert() {
    WebDriverWait wait = new WebDriverWait(driver, 5);
    if (wait.until(ExpectedConditions.alertIsPresent()) == null) {

        fail("Alert not showing as feedback for user");
    }//from www.  j a  v a2  s .c  om
    return this;
}

From source file:be.rubus.web.testing.widget.AlertHandling.java

License:Apache License

public void checkForNoAlert() {
    WebDriverWait wait = new WebDriverWait(driver, 5);
    try {//from  w w w. j ava 2  s.c om
        wait.until(ExpectedConditions.alertIsPresent());
        fail("Alert is showing and not expected to popup");
    } catch (TimeoutException te) {

        ; // OK we don't want to see the alert
    }

}

From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java

License:Open Source License

/**
 * Wait for the element to be present in the DOM, and displayed on the page.
 * And returns the first WebElement using the given method.
 * //from w  w w.  j  a  v  a2 s. c o m
 * @param WebDriver
 *            The driver object to be used
 * @param By
 *            selector to find the element
 * @param int The time in seconds to wait until returning a failure
 * 
 * @return WebElement the first WebElement using the given method, or null
 *         (if the timeout is reached)
 */
public static WebElement waitForElement(WebDriver driver, final By by, int timeOutInSeconds) {

    WebElement element;
    try {
        // To use WebDriverWait(), we would have to nullify
        // implicitlyWait().
        // Because implicitlyWait time also set "driver.findElement()" wait
        // time.
        // info from:
        // https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify
        // implicitlyWait()

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        element = wait.until(ExpectedConditions.visibilityOfElementLocated(by));

        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset
        // implicitlyWait
        return element; // return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java

License:Open Source License

/**
 * Wait for the element to be present in the DOM, regardless of being
 * displayed or not. And returns the first WebElement using the given
 * method./*w w  w.ja va  2  s.c  o m*/
 * 
 * @param WebDriver
 *            The driver object to be used
 * @param By
 *            selector to find the element
 * @param int The time in seconds to wait until returning a failure
 * 
 * @return WebElement the first WebElement using the given method, or null
 *         (if the timeout is reached)
 */
public static WebElement waitForElementPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    WebElement element;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify
        // implicitlyWait()

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        element = wait.until(ExpectedConditions.presenceOfElementLocated(by));

        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset
        // implicitlyWait
        return element; // return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:bg.pragmatic.lecture13mvn.waits.utils.WaitTool.java

License:Open Source License

/**
 * Wait for the List<WebElement> to be present in the DOM, regardless of
 * being displayed or not. Returns all elements within the current page DOM.
 * /* w  ww .ja  v  a2s .c o m*/
 * @param WebDriver
 *            The driver object to be used
 * @param By
 *            selector to find the element
 * @param int The time in seconds to wait until returning a failure
 * 
 * @return List<WebElement> all elements within the current page DOM, or
 *         null (if the timeout is reached)
 */
public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) {
    List<WebElement> elements;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify
        // implicitlyWait()

        WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
        wait.until((new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver driverObject) {
                return areElementsPresent(driverObject, by);
            }
        }));

        elements = driver.findElements(by);
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset
        // implicitlyWait
        return elements; // return the element
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}