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.digi.selenium.util.common.PageNavigation.java

protected void backToAccountsAndPaymentsPage() throws InterruptedException {
    tryToClickElementByXPath("//*[@id='menu-section']/div/ul/li[5]/a", 5).click();
    waitForPageLoad(100);//  w w w .ja v a2  s  .c  o  m
    Thread.sleep(500);
    waitForPageLoad(60);
    Thread.sleep(500);
    log.info("Success : Returned back on accounts and payments page ");
    waitgetForPageLoad(30).until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='content']/div[13]/div/div")));
    getDriver().findElement(By.xpath("//*[@id='content']/div[13]/div/div/div[2]/button[1]")).click();
    //*[@id="telenor-cancel-btn"]
    waitForPageLoad(30);
    getDriver().findElement(By.xpath("//*[@id='telenor-cancel-btn']")).click();
    waitForPageLoad(30);
}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected void backToAccountsAndPaymentsPagePrepaidBroadband() throws InterruptedException {
    tryToClickElementByXPath("//*[@id='menu-section']/div/ul/li[5]/a", 5).click();
    waitForPageLoad(100);//  w w w. j  av a2 s.  co m
    Thread.sleep(500);
    waitForPageLoad(60);
    Thread.sleep(500);
    log.info("Success : Returned back on accounts and payments page ");
    waitgetForPageLoad(30).until(
            ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='content']/div[13]/div/div")));
    getDriver().findElement(By.xpath("//*[@id='content']/div[13]/div/div/div[2]/button[1]")).click();
    //*[@id="telenor-cancel-btn"]
    waitForPageLoad(30);
}

From source file:com.digi.selenium.util.common.PageNavigation.java

protected WebElement tryToGetElementByXPath(String xpath, int maxtry) {
    Wait<WebDriver> waittable = new WebDriverWait(getDriver(), 30);
    WebElement element = null;/*ww  w. j  av  a2 s .  c o  m*/
    int trycount = 1;
    boolean breakit;
    while (trycount != maxtry) {
        breakit = true;
        try {
            element = waittable.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
        } catch (Exception e) {
            breakit = false;
            trycount++;

        }
        if (breakit == true)
            break;
    }
    return element;
}

From source file:com.easytox.automation.steps.LabClientImpl.java

@When("^Enter all the information in the Physician screen and click Submit$")
public void enter_all_the_information() {
    Physician.physicianUserName = StringUtils.generateRandom();
    selectOption(Physician.LAB_CLIENT_LOCATOR, LocatorType.ID, Physician.LAB_CLIENT);
    enterData(Physician.USER_NAME_LOCATOR, Physician.physicianUserName, LocatorType.NAME);
    enterData(Physician.PASSWORD_LOCATOR, Physician.PASSWORD, LocatorType.NAME);
    enterData(Physician.FIRST_NAME_LOCATOR, Physician.FIRST_NAME, LocatorType.NAME);
    enterData(Physician.LAST_NAME_LOCATOR, Physician.LAST_NAME, LocatorType.NAME);
    enterData(Physician.MIDDLE_NAME_LOCATOR, Physician.MIDDLE_NAME, LocatorType.NAME);
    enterData(Physician.MEDICAL_DEGREE_LOCATOR, Physician.MEDICAL_DEGREE, LocatorType.NAME);
    enterData(Physician.PHONE_NUMBER_LOCATOR, Physician.PHONE_NUMBER, LocatorType.NAME);
    enterData(Physician.EMAIL_ADDRESS_LOCATOR, Physician.EMAIL_ADDRESS, LocatorType.NAME);
    enterData(Physician.SALUTATION_LOCATOR, Physician.SALUTATION, LocatorType.NAME);
    enterData(Physician.FIRST_NAME_LOCATOR, Physician.FIRST_NAME, LocatorType.NAME);
    enterData(Physician.MEDICARE_NUMBER_LOCATOR, Physician.MEDICARE_NUMBER, LocatorType.NAME);
    enterData(Physician.MEDICAID_NUMBER_LOCATOR, Physician.MEDICAID_NUMBER, LocatorType.NAME);
    enterData(Physician.UPIN_NUMBER_LOCATOR, Physician.UPIN_NUMBER, LocatorType.NAME);
    enterData(Physician.STATE_LICENCE_LOCATOR, Physician.STATE_LICENCE, LocatorType.NAME);
    enterData(Physician.NPI_LOCATOR, Physician.NPI, LocatorType.NAME);

    selectOption(Physician.COMPOUND_PROFILE_LOCATOR, LocatorType.ID, Physician.COMPOUND_PROFILE);

    WebElement plusButton = MyWebDriverUtils.findElement(driver, Physician.PLUS_ONE_ICON_LOCATOR,
            LocatorType.CSS);/*from ww  w. j a  v a2s . c om*/
    WebDriverWait wait = new WebDriverWait(driver, TIME_OUT_IN_SECONDS);

    boolean flag = MyWebDriverUtils.waitInvisibilityOfElement(wait, CONTAINER_LOCATOR, LocatorType.ID);
    if (flag) {
        checkAndClick(plusButton);
    } else {
        Assert.fail("flag is false!");
    }

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(Physician.LOCATION_LOCATOR)));
    selectOption(Physician.LOCATION_LOCATOR, LocatorType.ID, Physician.LOCATION);

    WebElement el = MyWebDriverUtils.findElement(driver, Physician.CHECKBOX_ONE_LOCATOR, LocatorType.CSS);
    checkAndClick(el);

    plusButton = MyWebDriverUtils.findElement(driver, Physician.PLUS_TWO_ICON_LOCATOR, LocatorType.CSS);
    checkAndClick(plusButton);

    el = MyWebDriverUtils.findElement(driver, Physician.CHECKBOX_TWO_LOCATOR, LocatorType.CSS);
    checkAndClick(el);

    WebElement submit = MyWebDriverUtils.findElement(driver, Physician.SUBMIT_LOCATOR, LocatorType.CSS);
    checkAndClick(submit);

}

From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java

License:Open Source License

/**
 * Checks if the given element is displayed.
 * @param driver the driver/* ww w.j  ava 2  s .  co  m*/
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is displayed
 */
public static boolean isDisplayed(final WebDriver driver, final By locator, final CustomTimeout timeout) {

    boolean displayed = true;
    try {
        final WebDriverWait wait = new WebDriverWait(driver, timeout.getValue());
        wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
    } catch (TimeoutException te) {
        displayed = false;
    }
    return displayed;
}

From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java

License:Open Source License

/**
 * Checks if the given element is not displayed.
 * @param driver the driver/*from   ww w  .  ja va  2 s .  c om*/
 * @param locator the locator
 * @param timeout the timeout
 * @return true, if is not displayed
 */
public static boolean isNotDisplayed(final WebDriver driver, final By locator, final CustomTimeout timeout) {

    boolean notDisplayed = true;
    try {
        final WebDriverWait wait = new WebDriverWait(driver, timeout.getValue());
        wait.until(ExpectedConditions.not(ExpectedConditions.visibilityOfElementLocated(locator)));
    } catch (final WebDriverException te) {
        notDisplayed = false;
    }
    return notDisplayed;
}

From source file:com.econcept.selenium.method.Logout.java

License:Open Source License

@Override
public void activate() throws Exception {
    // If not even valid, return
    if (!isValid()) {
        return;/*ww w . j ava2 s  .  c om*/
    } // if

    try {
        String lXpathAction = "(//div[ ./a[starts-with(@class, 'gb_r gb_P gb_j identityWidgetIcon')]])[last()]";
        // Wait until element is visbile for 120 seconds
        WebDriverWait lWait = new WebDriverWait(mDriver, mTimeOut);
        Thread.sleep(WebDriverWait.DEFAULT_SLEEP_TIMEOUT);
        WebElement lElement = lWait
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(lXpathAction)));
        lElement.click();

        lXpathAction = "(//div[ ./a[starts-with(@href, '?logout&')]])[last()]";

        Thread.sleep(WebDriverWait.DEFAULT_SLEEP_TIMEOUT);
        lElement = lWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(lXpathAction)));
        lElement.click();
    } // try
    catch (Exception pException) {
        pException.printStackTrace();
        throw new Exception(pException);
    } // catch
}

From source file:com.elastica.webelements.BasePage.java

License:Apache License

public void waitForElementToBeVisible(final HtmlElement element) {
    Assert.assertNotNull(element, "Element can't be null");
    TestLogging.logWebStep(null, "wait for " + element.toString() + " to be visible.", false);

    WebDriverWait wait = new WebDriverWait(driver, explictWaitTimeout);
    wait.until(ExpectedConditions.visibilityOfElementLocated(element.getBy()));
}

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

License:Apache License

/**
 * testAddFolder01()./*from  www . j  ava  2  s  .  co m*/
 * add folder - missing name
 *
 * @throws Exception Exception
 */
@Test
public void testAddFolder01() throws Exception {
    // given
    // when
    findElementBy(By.id("folder_add_button")).click();

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("form-modal")));

    click(By.name("_eventId_next"));

    // then
    waitUntilPageSourceText("Field required");
}

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

License:Apache License

/**
 * testAddFolder02().//from   w ww. java  2  s . c  o m
 * add folder
 *
 * @throws Exception Exception
 */
@Test
public void testAddFolder02() throws Exception {
    // given
    String folder = "testfolder";

    // when
    findElementBy(By.id("folder_add_button")).click();

    getWait().until(ExpectedConditions.visibilityOfElementLocated(By.id("form-modal")));

    findElementBy("input", "data-valuekey", "name").sendKeys(folder);
    WebElement el = findElementBy(By.name("_eventId_next"));
    assertEquals("Add Folder", el.getText());
    el.click();

    // then
    getWait().until(ExpectedConditions.invisibilityOfElementLocated(By.id("form-modal")));

    int i = 0;
    final int elementCount = 2;
    List<WebElement> e = findElements(By.xpath("//table[@id='results']/tbody/tr/td"));
    assertEquals(elementCount, e.size());
    assertEquals("testfolder", e.get(i++).getText());
    assertEquals("", e.get(i++).getText());

    // when
    findElementBy(By.id("tablesearch")).sendKeys("testf1");
    findElementBy(By.id("buttonsearch")).click();

    // then
    e = findElements(By.xpath("//table[@id='results']/tbody/tr"));
    assertEquals(1, e.size());
    assertEquals("No Folder(s) found", e.get(0).getText());

    // when
    findElementBy(By.id("tablesearch")).clear();
    findElementBy(By.id("tablesearch")).sendKeys("testf");
    findElementBy(By.id("buttonsearch")).click();

    // then
    e = findElements(By.xpath("//table[@id='results']/tbody/tr"));
    assertEquals(1, e.size());
    assertEquals("testfolder", e.get(0).getText());
}