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:com.example.selenium.Table.java

public boolean validateTable() {

    boolean flag = true;
    List<WebElement> tablesRows;
    try {/*  w  ww.  j a v a 2s. c  om*/

        Select selectRows = new Select(tableDropDown);
        tableDropDown.click();
        Thread.sleep(2000);

        selectRows.selectByValue("10");
        tableDropDown.click();
        WebDriverWait wait = new WebDriverWait(selenium, 10);
        tablesRows = wait.until(ExpectedConditions
                .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 10));
        if (tablesRows.size() != 10) {
            flag = false;
        }

        Thread.sleep(1000);
        selectRows.selectByValue("25");
        tableDropDown.click();
        tablesRows = wait.until(ExpectedConditions
                .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 25));
        if (tablesRows.size() != 25) {
            flag = false;
        }

        Thread.sleep(1000);
        selectRows.selectByValue("50");
        tableDropDown.click();
        tablesRows = wait.until(ExpectedConditions
                .numberOfElementsToBe(By.xpath("//table[@id='dataTables-example']/tbody/tr"), 50));
        if (tablesRows.size() != 50) {
            flag = false;
        }

        Thread.sleep(2000);
        tableSearch.sendKeys("Presto");
        Thread.sleep(1000);
        WebElement element = new WebDriverWait(selenium, 5).until(new ExpectedCondition<WebElement>() {
            public WebElement apply(WebDriver d) {
                return d.findElement(By.xpath("//td[contains(text(),'Presto')]"));
            }
        });
        if (!element.getText().equals("Presto")) {
            flag = false;
        }

        return flag;
    } catch (InterruptedException ex) {
        Logger.getLogger(Table.class.getName()).log(Level.SEVERE, null, ex);
    }
    return flag;
}

From source file:com.formkiq.web.SeleniumTestBase.java

License:Apache License

/**
 * @param timeOutInSeconds long/*  www.  ja va  2  s. com*/
 * @return {@link WebDriverWait}
 */
public WebDriverWait getWait(final long timeOutInSeconds) {
    WebDriverWait block = new WebDriverWait(getDriver(), timeOutInSeconds);
    return block;
}

From source file:com.formkiq.web.SeleniumTestBase.java

License:Apache License

/**
 * Waiting for JQuery to Load.//from w  ww .ja  v  a 2 s . c o  m
 * @return boolean
 */
@SuppressWarnings("boxing")
public boolean waitForJSandJQueryToLoad() {

    WebDriverWait wait = new WebDriverWait(getDriver(), TIMEOUT);

    // wait for jQuery to load
    ExpectedCondition<Boolean> jQuery = new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(final WebDriver webdriver) {
            try {
                return ((Long) ((JavascriptExecutor) webdriver).executeScript("return jQuery.active") == 0);
            } catch (Exception e) {
                // no jQuery present
                return true;
            }
        }
    };

    // wait for Javascript to load
    ExpectedCondition<Boolean> jsLoad = new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(final WebDriver webdriver) {
            return ((JavascriptExecutor) webdriver).executeScript("return document.readyState").toString()
                    .equals("complete");
        }
    };

    return wait.until(jQuery) && wait.until(jsLoad);
}

From source file:com.fpt.datht.iap.AutoIAP.java

public static void loginGoogle(String user, String pass) {
    System.setProperty("webdriver.chrome.driver", "/chromedriver.exe");

    driver = new ChromeDriver();

    //  driver = new HtmlUnitDriver(true);
    driver.navigate().to("http://iap.fpt.edu.vn/hlogin.php?provider=Google");

    new WebDriverWait(driver, 360).until(ExpectedConditions.titleIs("Sign in - Google Accounts"));
    el = driver.findElement(By.id("Email"));
    el.sendKeys(user);// w  w w  .j a  v a  2  s.  co m
    el = driver.findElement(By.id("next"));
    el.click();

    new WebDriverWait(driver, 360).until(ExpectedConditions.presenceOfElementLocated(By.id("Passwd")));

    el = driver.findElement(By.id("Passwd"));
    el.sendKeys(pass);
    el = driver.findElement(By.id("signIn"));
    el.click();

}

From source file:com.fpt.datht.iap.AutoIAP.java

public static void getDataFromServer(String className) {
    int c = 0;/*from   w  w w.  j a  va 2 s .  co m*/
    slots = new String[10];
    students = new LinkedList<>();
    new WebDriverWait(driver, 360).until(ExpectedConditions.titleIs("IAP"));
    driver.get("http://iap.fpt.edu.vn/activity");

    new WebDriverWait(driver, 360).until(ExpectedConditions.urlToBe("http://iap.fpt.edu.vn/activity/"));

    List<WebElement> els = driver.findElements(By.tagName("a"));
    System.out.println("Size a:" + els.size());
    for (WebElement e : els) {
        //  System.out.println(e.getText());
        if (e.getText().contains(className)) {

            slots[c] = e.getAttribute("href").replaceAll("http://iap.fpt.edu.vn/activity/index.php",
                    "http://iap.fpt.edu.vn/attendance/add.php");
            c++;
            count = c;
            // System.out.println(main);

        }
    }
    if (slots.length == 0)
        return;
    driver.get(slots[0]);

    try {
        new WebDriverWait(driver, 5)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));

    } catch (TimeoutException ex) {
        driver.get(slots[0].replaceAll("add.php", "edit.php"));

    }
    //Auto Check Slot 1
    if (autoCheckSlot1) {
        List<WebElement> elsInput = driver.findElements(By.xpath(".//input[@type='radio' and @value='1' ]"));
        autoCheckAll(elsInput);
    }

    //Wating for submit
    new WebDriverWait(driver, 5000)
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//font[@color='green']")));
    driver.get(slots[0].replaceAll("add.php", "edit.php"));
    //GET All checked
    List<WebElement> elsInputChecked = driver
            .findElements(By.xpath(".//input[@type='radio' and @value='1' and @checked]"));

    System.out.println("Size input checked:" + elsInputChecked.size());

    elsInputChecked.stream().map((e) -> {
        Student student = new Student();
        student.name = e.getAttribute("name");
        return student;
    }).forEach(students::add);

}

From source file:com.fpt.datht.iap.AutoIAP.java

public static void autoCheck() {

    for (int c = 1; c < count; c++) {

        driver.get(slots[c]);//from  ww w.ja v  a 2 s  .  c o m
        try {
            new WebDriverWait(driver, 5)
                    .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));

        } catch (TimeoutException ex) {
            driver.get(slots[c].replaceAll("add.php", "edit.php"));

        }
        new WebDriverWait(driver, 10)
                .until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//input[@type='submit']")));
        for (Student st : students) {

            List<WebElement> els = driver.findElements(By.name(st.name));
            els.stream().filter((e) -> (e.getAttribute("value").equals("1"))).forEach((e) -> {
                e.click();
            });
        }
        el = driver.findElement(By.xpath(".//input[@type='submit']"));
        el.click();
        try {
            new WebDriverWait(driver, 3).until(
                    ExpectedConditions.invisibilityOfElementLocated(By.xpath(".//input[@type='submit']")));
        } catch (TimeoutException ex) {
            break;

        }

    }

}

From source file:com.fullteaching.backend.e2e.BrowserUser.java

License:Apache License

protected void newWaiter(int timeOfWait) {
    this.waiter = new WebDriverWait(this.driver, timeOfWait);
}

From source file:com.fullteaching.backend.e2e.BrowserUser.java

License:Apache License

protected void configureDriver() {
    this.waiter = new WebDriverWait(this.driver, this.timeOfWaitInSeconds);
}

From source file:com.gargoylesoftware.htmlunit.HttpWebConnection3Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from www .  j ava  2  s.  c  o  m
 */
@Test
@Alerts(CHROME = { "Host", "Connection", "Accept", "User-Agent", "Referer", "Accept-Encoding",
        "Accept-Language", "Cookie" }, FF = { "Host", "User-Agent", "Accept", "Accept-Language",
                "Accept-Encoding", "Referer", "Cookie", "Connection" }, IE = { "Accept", "Referer",
                        "Accept-Language", "User-Agent", "Accept-Encoding", "Host", "DNT", "Connection",
                        "Cookie" })
@NotYetImplemented(IE)
public void headers_cookie_referer() throws Exception {
    final String htmlResponse = "<a href='2.html'>Click me</a>";
    final String response = "HTTP/1.1 200 OK\r\n" + "Content-Length: " + htmlResponse.length() + "\r\n"
            + "Content-Type: text/html\r\n" + "Set-Cookie: name=value\r\n" + "\r\n" + htmlResponse;

    primitiveWebServer_ = new PrimitiveWebServer(PORT, response.getBytes());
    primitiveWebServer_.start();
    final WebDriver driver = getWebDriver();

    driver.get("http://localhost:" + PORT + "");
    driver.findElement(By.linkText("Click me")).click();

    final Wait<WebDriver> wait = new WebDriverWait(driver, 5);
    wait.until(currentUrlContains("2.html"));

    int index = 1;
    String request;
    do {
        request = primitiveWebServer_.getRequests().get(index++);
    } while (request.contains("/favicon.ico"));

    final String[] headers = request.split("\\r\\n");
    final String[] result = new String[headers.length - 1];
    for (int i = 0; i < result.length; i++) {
        final String header = headers[i + 1];
        result[i] = header.substring(0, header.indexOf(':'));
    }
    assertEquals(Arrays.asList(getExpectedAlerts()).toString(), Arrays.asList(result).toString());
}

From source file:com.gdf.managedBean.TendererInvitationBeanTest.java

@Test
public void send() {

    email = driver.findElement(By.xpath("//input[contains(@id, 'mailForm:email')]"));
    sendButton = driver.findElement(By.xpath("//button[contains(@id, 'mailForm:send')]"));

    email.clear();/*from w w w.  jav a2  s .c o m*/
    email.sendKeys("guendouzbachir@hotmail.com");

    sendButton.click();

    // Test
    WebElement growlTitle = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.className("ui-growl-title")));

    // Verification
    assertEquals(growlTitle.getText(), "Message envoy!");

}