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

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

Introduction

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

Prototype

public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) 

Source Link

Document

An expectation for checking that an element is present on the DOM of a page and visible.

Usage

From source file:com.liferay.faces.test.selenium.browser.internal.ExpectedConditionsUtil.java

License:Open Source License

public static ExpectedCondition<?> ifNecessaryExpectElementDisplayed(
        ExpectedCondition<?> originalExpectedCondition, boolean elementMustBeDisplayed, By locator) {

    ExpectedCondition<?> expectedCondition = originalExpectedCondition;

    if (elementMustBeDisplayed) {

        ExpectedCondition<WebElement> elementDisplayed = ExpectedConditions.visibilityOfElementLocated(locator);
        expectedCondition = ExpectedConditions.and(originalExpectedCondition, elementDisplayed);
    }//from w  w  w . ja va 2  s  . c o m

    return expectedCondition;
}

From source file:com.liferay.faces.test.selenium.browser.internal.WaitingAsserterImpl.java

License:Open Source License

@Override
public void assertElementDisplayed(String elementXpath) {
    assertTrue(ExpectedConditions.visibilityOfElementLocated(By.xpath(elementXpath)));
}

From source file:com.liferay.faces.test.util.TesterBase.java

License:Open Source License

public void waitForElement(WebDriver browser, String xpath) {
    WebDriverWait wait = new WebDriverWait(browser, 10);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.ByXPath.xpath(xpath)));
}

From source file:com.mokona.wait.WaitTool.java

License:Open Source License

public WebElement waitForElement(final By by, int timeOutInSeconds) {
    webDriver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);

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

    webDriver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS);

    return element;
}

From source file:com.mycompany.selenium.SeleniumTests.java

@Test
public void test5() throws Exception {

    WebElement editButton = null;/*from w  w w  .  j  a va2 s .c o  m*/
    driver.get("http://localhost:3000");
    WebDriverWait wait = new WebDriverWait(driver, WAIT_MAX);
    wait.until(ExpectedConditions.visibilityOfElementLocated((By.tagName("thead"))));
    driver.switchTo().parentFrame();

    WebElement table = driver.findElement(By.tagName("tbody"));
    List<WebElement> rows = table.findElements(By.tagName("tr"));

    //loop through rows to find car with id "938"
    for (int i = 0; i < rows.size(); i++) {
        if (rows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            editButton = rows.get(i);
            break;
        }
    }

    editButton = editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0);
    editButton.click();

    driver.findElement(By.id("description")).clear();
    wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("description"))));

    driver.findElement(By.id("description")).sendKeys("cool cars");
    driver.findElement(By.id("save")).click();

    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement updatedTable = d.findElement(By.tagName("tbody"));
        List<WebElement> updatedRows = updatedTable.findElements(By.tagName("tr"));

        String editedRow = null;
        //loop through rows to find car with id "938"
        for (int i = 0; i < updatedRows.size(); i++) {
            if (updatedRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
                editedRow = updatedRows.get(i).findElements(By.tagName("td")).get(5).getText();
                break;
            }
        }
        assertThat(editedRow, is("cool cars"));
        return true;
    });
}

From source file:com.mycompany.selenium.SeleniumTests.java

@Test
//Click the new Car Button, and add the following values for a new car
public void test7() throws Exception {
    WebDriverWait wait = new WebDriverWait(driver, WAIT_MAX);
    wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("new"))));

    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("year")).sendKeys("2008");
    driver.findElement(By.id("registered")).sendKeys("2002-5-5");
    driver.findElement(By.id("make")).sendKeys("Kia");
    driver.findElement(By.id("model")).sendKeys("Rio");
    driver.findElement(By.id("description")).sendKeys("As new");
    driver.findElement(By.id("price")).sendKeys("31000");

    //save the new car
    driver.findElement(By.id("save")).click();

    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement updatedTable = d.findElement(By.tagName("tbody"));
        List<WebElement> updatedRows = updatedTable.findElements(By.tagName("tr"));
        //row count should be 6
        assertThat(updatedRows.size(), is(6));

        //new car should be on row 6, check year
        assertThat(updatedRows.get(5).findElements(By.tagName("td")).get(1).getText(), is("2008"));
        //model is Rio
        assertThat(updatedRows.get(5).findElements(By.tagName("td")).get(4).getText(), is("Rio"));

        return true;
    });//from   w w w .  j a v a 2  s .c o  m
}

From source file:com.nowsprinting.hellotesting.appiumtest.appium.page.DetailPage.java

License:Apache License

/**
 * ???????//w  w  w. java 2  s.c o  m
 * 
 * @return ?????true??????????false?
 */
public boolean waitUntilLoad() {
    // ???????????
    try {
        mWait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId("name textfield")));
    } catch (TimeoutException e) {
        return false;
    }
    return true;
}

From source file:com.nowsprinting.hellotesting.appiumtest.selendroid.page.SelendroidDetailPage.java

License:Apache License

@Override
public boolean waitUntilLoad() {
    // ???????????
    try {//from   w w w  . j  a va2 s .  com
        mWait.until(ExpectedConditions.visibilityOfElementLocated(By.name("name textfield")));
    } catch (TimeoutException e) {
        return false;
    }
    return true;
}

From source file:com.oracle.amc.sqe.util.webui.WebUIPage.java

License:Open Source License

public void wait(By waitElement) {
    if (waitElement != null) {
        wait.until(ExpectedConditions.visibilityOfElementLocated(waitElement));
    }
}

From source file:com.pages.CompanyLoginpage.java

public static void CompanyLogin(WebDriver driver, String Companynumber) throws InterruptedException {
    String url = driver.getCurrentUrl();
    if (URL.equalsIgnoreCase(url)) {
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
        common.Wait_Until_ElementVisible(driver, LicenseAgreement_popup);
        driver.findElement(By.xpath("//button[@id='btnEULAAgree']")).click();
        //Thread.sleep(1000);
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
    } else {//from ww w.  jav  a  2  s  .  co m
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript(String.format("window.localStorage.clear();"));
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.manage().deleteAllCookies();
        Actions act = new Actions(driver);
        act.sendKeys(Keys.CONTROL.F5).perform();
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
        driver.findElement(By.xpath("//button[@id='btnEULAAgree']")).click();
        //Thread.sleep(1000);
        driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);

    }

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("return document.readyState").equals("complete");
    //Thread.sleep(1000);
    WebDriverWait ww = new WebDriverWait(driver, 30);
    ww.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(AccessKey_fld_xpath)));
    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
    driver.findElement(By.xpath(AccessKey_fld_xpath)).sendKeys(Companynumber);
    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
    driver.findElement(By.xpath(Download_btn_xpath)).click();
    driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
    // Thread.sleep(500);
    ww.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(HomePage_NavBar)));
}