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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:org.cerberus.serviceEngine.impl.WebDriverService.java

License:Open Source License

private WebElement getSeleniumElement(Session session, String input, boolean visible, boolean clickable) {
    By locator = this.getIdentifier(input);
    MyLogger.log(RunTestCaseService.class.getName(), Level.DEBUG, "Waiting for Element : " + input);
    try {/*from   ww  w  .  j a v  a  2s.  c om*/
        WebDriverWait wait = new WebDriverWait(session.getDriver(), session.getDefaultWait());
        if (visible) {
            if (clickable) {
                wait.until(ExpectedConditions.elementToBeClickable(locator));
            } else {
                wait.until(ExpectedConditions.visibilityOfElementLocated(locator));
            }
        } else {
            wait.until(ExpectedConditions.presenceOfElementLocated(locator));
        }
    } catch (TimeoutException exception) {
        MyLogger.log(RunTestCaseService.class.getName(), Level.FATAL,
                "Exception waiting for element :" + exception);
        throw new NoSuchElementException(input);
    }
    MyLogger.log(RunTestCaseService.class.getName(), Level.DEBUG, "Finding Element : " + input);
    return session.getDriver().findElement(locator);
}

From source file:org.cerberus.serviceEngine.impl.WebDriverService.java

License:Open Source License

@Override
public MessageEvent doSeleniumActionWait(Session session, String object, String property) {
    MessageEvent message;//from www. jav  a 2s . co m
    try {
        if (!StringUtil.isNull(property)) {
            if (StringUtil.isNumeric(property)) {
                try {
                    Thread.sleep(Integer.parseInt(property));
                } catch (InterruptedException exception) {
                    MyLogger.log(WebDriverService.class.getName(), Level.INFO, exception.toString());
                    message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT);
                    message.setDescription(message.getDescription().replaceAll("%TIME%", property));
                    return message;
                }
                message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME);
                message.setDescription(message.getDescription().replaceAll("%TIME%", property));
                return message;
            } else {
                try {
                    WebDriverWait wait = new WebDriverWait(session.getDriver(), TIMEOUT_WEBELEMENT);
                    wait.until(ExpectedConditions.presenceOfElementLocated(this.getIdentifier(property)));
                    message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT);
                    message.setDescription(message.getDescription().replaceAll("%ELEMENT%", property));
                    return message;
                } catch (NoSuchElementException exception) {
                    message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT);
                    message.setDescription(message.getDescription().replaceAll("%ELEMENT%", property));
                    MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString());
                    return message;
                }
            }
        } else if (!StringUtil.isNull(object)) {
            if (StringUtil.isNumeric(object)) {
                try {
                    Thread.sleep(Integer.parseInt(object));
                } catch (InterruptedException exception) {
                    MyLogger.log(WebDriverService.class.getName(), Level.INFO, exception.toString());
                    message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT);
                    message.setDescription(message.getDescription().replaceAll("%TIME%", object));
                    return message;
                }
                message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME);
                message.setDescription(message.getDescription().replaceAll("%TIME%", object));
                return message;
            } else {
                try {
                    WebDriverWait wait = new WebDriverWait(session.getDriver(), TIMEOUT_WEBELEMENT);
                    wait.until(ExpectedConditions.presenceOfElementLocated(this.getIdentifier(object)));
                    message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT);
                    message.setDescription(message.getDescription().replaceAll("%ELEMENT%", object));
                    return message;
                } catch (NoSuchElementException exception) {
                    message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT);
                    message.setDescription(message.getDescription().replaceAll("%ELEMENT%", object));
                    MyLogger.log(WebDriverService.class.getName(), Level.DEBUG, exception.toString());
                    return message;
                }
            }
        } else {
            try {
                Thread.sleep(TIMEOUT_MILLIS);
            } catch (InterruptedException exception) {
                MyLogger.log(WebDriverService.class.getName(), Level.INFO, exception.toString());
                message = new MessageEvent(MessageEventEnum.ACTION_FAILED_WAIT);
                message.setDescription(
                        message.getDescription().replaceAll("%TIME%", Integer.toString(TIMEOUT_MILLIS)));
                return message;
            }
            message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_WAIT_TIME);
            message.setDescription(
                    message.getDescription().replaceAll("%TIME%", Integer.toString(TIMEOUT_MILLIS)));
            return message;
        }
    } catch (WebDriverException exception) {
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_SELENIUM_CONNECTIVITY);
        MyLogger.log(WebDriverService.class.getName(), Level.FATAL, exception.toString());
        return message;
    }
}

From source file:org.cloudfoundry.identity.uaa.integration.feature.InvitationsIT.java

License:Open Source License

@Test
public void acceptInvitation_for_samlUser() throws Exception {
    webDriver.get(baseUrl + "/logout.do");
    String email = "testinvite@test.org";
    String code = createInvitation(email, email, "http://localhost:8080/app/", "simplesamlphp");

    String invitedUserId = IntegrationTestUtils.getUserIdByField(scimToken, baseUrl, "simplesamlphp", "email",
            email);//  w ww  .  ja v a 2s . c  o  m
    IntegrationTestUtils.createIdentityProvider("simplesamlphp", true, baseUrl, serverRunning);

    webDriver.get(baseUrl + "/invitations/accept?code=" + code);
    webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
    webDriver.findElement(By.name("username")).clear();
    webDriver.findElement(By.name("username")).sendKeys("user_only_for_invitations_test");
    webDriver.findElement(By.name("password")).sendKeys("saml");
    WebElement loginButton = webDriver.findElement(By.xpath("//input[@value='Login']"));
    loginButton.click();
    //wait until UAA page has loaded
    new WebDriverWait(webDriver, 45)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("application_authorization")));
    String acceptedUsername = IntegrationTestUtils.getUsernameById(scimToken, baseUrl, invitedUserId);
    //webdriver follows redirects so we should be on the UAA authorization page
    assertEquals("user_only_for_invitations_test", acceptedUsername);
}

From source file:org.craftercms.web.basic.ComponentTest.java

@Test
public void testDragAndDrop() throws InterruptedException {
    String image = "/requiredImage.png";

    // Navigate to About page
    //driver.navigate().to(seleniumProperties.getProperty("craftercms.base.url") + aboutPage);
    CStudioSeleniumUtil.navigateToAndWaitForPageToLoad(driver,
            seleniumProperties.getProperty("craftercms.base.url") + aboutPage);

    CStudioSeleniumUtil.clickOn(driver, By.cssSelector("#acn-preview-tools-container"));

    new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
        @Override/* ww  w .  j a v  a 2  s  .  c o m*/
        public Boolean apply(WebDriver d) {
            return d.findElement(By.cssSelector("#preview-tools-panel-container")).isDisplayed();
        }
    });

    List<WebElement> options = (new WebDriverWait(driver, 10)).until(ExpectedConditions
            .presenceOfAllElementsLocatedBy(By.cssSelector("#preview-tools-panel-container .contracted")));

    options.get(1).click();

    new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return d.findElement(By.id("placeholder-zone-bottomPromos1")).isDisplayed();
        }
    });

    WebElement source = driver.findElement(By.id("yui-gen4"));
    WebElement target = driver.findElement(By.id("bottomPromos1"));

    Actions builder = new Actions(driver);
    Action dragAndDrop = builder.dragAndDrop(source, target).build();
    dragAndDrop.perform();

    WebElement element = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("in-context-edit-editor")));
    //Check the modal window
    assertTrue(element != null);

    driver.switchTo().frame(element);

    //Upload an Image
    CStudioSeleniumUtil.clickOn(driver, By.cssSelector("#image input[value='Add']"));

    element = (new WebDriverWait(driver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#cstudio-wcm-popup-div")));
    //Check the modal window
    assertTrue(element != null);

    driver.findElement(By.cssSelector("#uploadFileNameId")).sendKeys(assetsPath + image);
    driver.findElement(By.cssSelector("#uploadButton")).click();

    new WebDriverWait(driver, 10).until(new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver d) {
            return !d.findElement(By.cssSelector("#image .datum")).getAttribute("value").isEmpty();
        }
    });

    driver.findElement(By.cssSelector("#cstudioSaveAndClose")).click();

    driver.switchTo().defaultContent();
}

From source file:org.eclipse.che.selenium.pageobject.ConfigureClasspath.java

License:Open Source License

/**
 * wait item in 'Select Path' form// w w  w.ja v a 2  s .c om
 *
 * @param item is the name of the item
 */
public void waitItemInSelectPathForm(String item) {
    loader.waitOnClosed();
    new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC).until(
            ExpectedConditions.presenceOfElementLocated(By.xpath(String.format(ITEM_SELECT_PATH_FORM, item))));
    loader.waitOnClosed();
}

From source file:org.eclipse.che.selenium.pageobject.dashboard.DashboardFactory.java

License:Open Source License

/**
 * Select action on 'Add action' window/*from   ww w  .java  2s  .  co m*/
 *
 * @param addAction name of Action
 */
public void selectAction(AddAction addAction) {
    WaitUtils.sleepQuietly(1);
    new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath(AddActionWindow.ACTION_XPATH))).click();
    new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
            .until(ExpectedConditions.presenceOfElementLocated(
                    By.xpath(String.format(AddActionWindow.ACTION_SELECT_XPATH, addAction.actionName))))
            .click();
}

From source file:org.eclipse.che.selenium.pageobject.dashboard.DashboardFactory.java

License:Open Source License

/**
 * Enter param value on 'Add action' window
 *
 * @param paramValue value of param//w  ww  .j a v  a2s  .  c  o  m
 */
public void enterParamValue(String paramValue) {
    new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath(AddActionWindow.PARAM_XPATH))).clear();
    loader.waitOnClosed();
    new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath(AddActionWindow.PARAM_XPATH)))
            .sendKeys(paramValue);
    loader.waitOnClosed();
    new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC).until(ExpectedConditions
            .textToBePresentInElementValue(By.xpath(AddActionWindow.PARAM_XPATH), paramValue));
}

From source file:org.eclipse.che.selenium.pageobject.dashboard.organization.OrganizationPage.java

License:Open Source License

public void checkMemberExistsInMembersList(String email) {
    redrawUiElementsTimeout.until(ExpectedConditions
            .presenceOfElementLocated(By.xpath(String.format(Locators.MEMBERS_LIST_ITEM_XPATH, email))));
}

From source file:org.eclipse.che.selenium.pageobject.debug.PhpDebugConfig.java

License:Open Source License

/**
 * Check if state of "break at first line" checkbox equals to breakAtFirstLine parameter.
 *
 * @param breakAtFirstLine/*from  w  ww.  j  av  a2s.co  m*/
 */
private void ensureBreakAtFirstLineCheckboxState(boolean breakAtFirstLine) {
    boolean isSelected = new WebDriverWait(seleniumWebDriver, REDRAW_UI_ELEMENTS_TIMEOUT_SEC)
            .until(ExpectedConditions
                    .presenceOfElementLocated(By.xpath(Locators.BREAK_AT_FIRST_LINE_CHECKBOX_XPATH)))
            .isSelected();

    if (isSelected != breakAtFirstLine) {
        breakAtFirstLineLabel.click();
    }
}

From source file:org.eclipse.che.selenium.pageobject.Events.java

License:Open Source License

/** wait project events area */
public void waitOpened() {
    new WebDriverWait(seleniumWebDriver, ELEMENT_TIMEOUT_SEC)
            .until(ExpectedConditions.presenceOfElementLocated(By.id(EVENTS_AREA)));
}