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:budget.WebDriverManager.java

private static void refreshAccountsAmEx() {
    int attempts = 3;
    int attempt = 1;
    Boolean isDownloaded = false;
    List<String> credentials = getCredentials(7);

    while ((attempt <= attempts) && !isDownloaded) {
        try {//from ww  w .j a  va 2  s . c  om
            driver = new FirefoxDriver();
            driver.manage().window().setPosition(new Point(-2000, 0));
            wait = new WebDriverWait(driver, timeout);
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit")
                    .setLevel(java.util.logging.Level.OFF);
            java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);

            driver.get("Http://www.americanexpress.com");
            driver.findElement(By.id("Username")).clear();
            driver.findElement(By.id("Username")).sendKeys(credentials.get(0));
            driver.findElement(By.id("Password")).clear();
            driver.findElement(By.id("Password")).sendKeys(credentials.get(1));
            driver.findElement(By.id("loginLink")).click();

            //Total amount       
            waitAndClick(driver, wait, By.id("avlbleCreditAsterick"));
            waitForElement(wait, By.id("availCreditValue"));
            String balanceStr = driver.findElement(By.id("availCreditValue")).getText();
            String limitStr = driver.findElement(By.id("ttlCreditValue")).getText();
            double amount = convertStringAmountToDouble(balanceStr) - convertStringAmountToDouble(limitStr);
            addTotal(stmt, getTimestamp(), 7, amount, taLog);

            //Transactions
            waitAndClick(driver, wait, By.id("MYCA_PC_Statements2"));
            waitAndClick(driver, wait, By.id("expandTP"));
            waitAndClick(driver, wait, By.id("anon_7"));//January 1 to Present
            wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.id("expandTP"))));

            //Pending transactions
            driver.findElement(By.id("recentTrans")).click();
            waitForElement(wait, By.className("pendingetd-helptxt"));
            runQueryAmEx(driver, wait, true);

            //Posted transactions
            runQueryAmEx(driver, wait, false);

            driver.findElement(By.id("iNLogBtn")).click();
            driver.quit();

            isDownloaded = true;
        } catch (Exception ex) {
            driver.quit();
            trace(ex.getMessage(), taLog);
            clearBatch(stmt);
            attempt++;
        }
        ;
    }
    trace((isDownloaded ? "Downloaded" : "Not downloaded") + " from " + attempt
            + ((attempt == 1) ? " attempt" : " attemps"), taLog);

    //Execution
    executeBatch(stmt, taLog);
}

From source file:businesscomponents.ReportcomparisonComponents1.java

public boolean waitForElement(WebDriver driver, By by, int time) {
    boolean flag;
    try {/*from  w  w w .j av a 2 s  . c o  m*/
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        assertTrue((isElementPresent(driver, by)));
        WebDriverWait wait = new WebDriverWait(driver, time);
        WebElement myElement = wait.until(ExpectedConditions.visibilityOfElementLocated(by));
        driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
        if (myElement != null)
            flag = true;
        else
            flag = false;

    } catch (Exception e) {
        System.out.println(e.toString());
        flag = false;
    }
    return flag;
}

From source file:businesscomponents.ReportcomparisonComponents1.java

public static boolean waitForElementForSecond(WebDriver driver, By by, int time) {
    boolean flag;
    try {/*  w ww  .j av  a2 s.  co m*/
        WebDriverWait wait = new WebDriverWait(driver, time);
        WebElement myElement = wait.until(ExpectedConditions.visibilityOfElementLocated(by));
        driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
        if (myElement != null)
            flag = true;
        else
            flag = false;

    } catch (Exception e) {
        System.out.println(e.toString());
        flag = false;
    }
    return flag;
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public UserStorageBrowserPage(final WebDriver driver) throws Exception {
    super(driver);
    this.driver = driver;

    // The beacon-progress bar displays "Transferring Data" while it's loading
    // the page. Firefox doesn't display whole list until the bar is green, and
    // that text is gone. Could be this test isn't sufficient but it works
    // to have intTestFirefox not fail.
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.textToBe(By.className("beacon-progress"), ""));

    PageFactory.initElements(driver, this);
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public void clickFolder(String folderName) {
    WebElement folder = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(
            xpath("//*[@id=\"beacon\"]/tbody/tr/td/a[text()[contains(.,'" + folderName + "')]]")));

    System.out.println("Folder to be clicked: " + folder.getText());
    folder.click();/*from www.j av a 2s  .com*/
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public void clickFolderForRow(int rowNum) throws Exception {
    WebElement firstCheckbox = (new WebDriverWait(driver, 10)).until(ExpectedConditions
            .elementToBeClickable(xpath("//*[@id=\"beacon\"]/tbody/tr[" + rowNum + "]/td[2]/a")));
    click(firstCheckbox);//ww w  .ja va 2  s  . c  o  m
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public void createNewFolder(String foldername) throws Exception {
    newdropdownButton.click();//from   w ww  . jav  a 2  s .  com
    newFolder.click();
    WebElement newfolderInput = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.elementToBeClickable(By.id("fname")));

    sendKeys(newfolderInput, foldername);

    WebElement createFolderButton = find(xpath("//button[contains(text(),\"Create Folder\")]"));
    createFolderButton.click();

    if (isJqiMsgShowing(CONFIRMATION_MSG)) {
        clickButton(OK);
    } else {
        throw new Exception("Could not create folder " + foldername);
    }
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public String togglePublicAttributeForRow(int rowNum) throws Exception {
    String currentPermission = "";
    WebElement editIcon = find(xpath("//span[contains(@class, 'glyphicon-edit')]"));
    editIcon.click();/* w  ww .ja va  2 s .  c o  m*/
    WebElement permissionCheckbox = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.elementToBeClickable(By.id("publicPermission")));

    currentPermission = permissionCheckbox.getAttribute("checked");
    click(permissionCheckbox);
    clickButton(SAVE);

    // confirm folder delete
    if (isJqiMsgShowing(SUCCESSFUL)) {
        clickButton(OK);
    } else {
        throw new Exception("Permissions editing not successful for row : " + rowNum);
    }

    return currentPermission;
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public void clickCheckboxForRow(int rowNum) throws Exception {
    WebElement firstCheckbox = (new WebDriverWait(driver, 10)).until(ExpectedConditions
            .elementToBeClickable(xpath("//*[@id=\"beacon\"]/tbody/tr[" + rowNum + "]/td[1]")));
    click(firstCheckbox);//from w  w w.j a v a  2 s . c  o m
}

From source file:ca.nrc.cadc.UserStorageBrowserPage.java

License:Open Source License

public boolean isJqiMsgShowing(String message) {
    try {/*from w w w . ja v  a  2s. c  om*/
        WebElement jqiMsg = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(
                xpath("//div[contains(@class, \"jqimessage\") and contains(text(), \"" + message + "\")]")));
        return true;
    } catch (Exception e) {
        return false;
    }
}