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.pentaho.ctools.main.LoginPentaho.java

License:Open Source License

@Test
public void testLoginPentaho() throws Exception {
    driver.get(baseUrl + "Login");

    //Wait for form display
    wait.until(ExpectedConditions/*from ww  w.j a v a 2 s .c  o  m*/
            .visibilityOfElementLocated(By.xpath("//div[@id='login-form-container']/div/h1")));

    assertEquals("User Console",
            driver.findElement(By.xpath("//div[@id='login-form-container']/div/h1")).getText());
    driver.findElement(By.id("j_username")).clear();
    driver.findElement(By.id("j_username")).sendKeys("admin");
    driver.findElement(By.id("j_password")).clear();
    driver.findElement(By.id("j_password")).sendKeys("password");
    driver.findElement(By.cssSelector("button.btn")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//iframe[@id='home.perspective']")));
    assertNotNull(driver.findElement(By.xpath("//iframe[@id='home.perspective']")));
    assertEquals("Pentaho User Console", driver.getTitle());

    //Go to the Home Perspective [IFRAME]
    driver.switchTo().frame("home.perspective");

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='well sidebar']")));
    driver.findElement(By.xpath("//div[@class='well sidebar']/button")).click();

    driver.switchTo().defaultContent();

    wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("applicationShell")));
    wait.until(ExpectedConditions
            .visibilityOfAllElementsLocatedBy(By.xpath("//iframe[@id='browser.perspective']")));
    driver.switchTo().frame("browser.perspective");
    wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@id='fileBrowser']")));
    wait.until(
            ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@id='fileBrowserFolders']")));

    assertNotNull(driver.findElement(By.xpath("//div[@id='fileBrowser']")));
}

From source file:org.rstudio.studio.selenium.DataImportTests.java

License:Open Source License

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    driver_ = RStudioWebAppDriver.start();

    (new WebDriverWait(driver_, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.className("gwt-MenuBar")));
}

From source file:org.rstudio.studio.selenium.DialogTestUtils.java

License:Open Source License

public static WebElement waitForModalToAppear(WebDriver driver) {
    return (new WebDriverWait(driver, 2))
            .until(ExpectedConditions.presenceOfElementLocated(By.className("gwt-DialogBox-ModalDialog")));
}

From source file:org.rstudio.studio.selenium.MenuNavigator.java

License:Open Source License

public static WebElement getMenuItem(WebDriver driver, String level1, String level2) {
    WebElement menuBar = driver.findElement(By.className("gwt-MenuBar"));
    WebElement menu1 = findMenuItemByName(menuBar, level1);
    menu1.click();//from   ww w . j a va 2s.c o m

    WebElement menu1Popup = (new WebDriverWait(driver, 1))
            .until(ExpectedConditions.presenceOfElementLocated(By.className("gwt-MenuBarPopup")));

    return findMenuItemByName(menu1Popup, level2);
}

From source file:org.rstudio.studio.selenium.RConsoleInteraction.java

License:Open Source License

@Test
public void testPlotGeneration() {
    ConsoleTestUtils.resumeConsoleInteraction(driver_);

    Actions plotCars = new Actions(driver_);
    plotCars.sendKeys(Keys.ESCAPE + "plot(cars)" + Keys.ENTER);
    plotCars.perform();/*from   w  ww .  ja v a  2s.c o m*/

    // Wait for the Plot window to activate
    final WebElement plotWindow = (new WebDriverWait(driver_, 5)).until(ExpectedConditions
            .presenceOfElementLocated(By.id(ElementIds.getElementId(ElementIds.PLOT_IMAGE_FRAME))));

    // Wait for a plot to appear in the window
    Assert.assertEquals(plotWindow.getTagName(), "iframe");
    driver_.switchTo().frame(plotWindow);

    (new WebDriverWait(driver_, 5)).until(ExpectedConditions.presenceOfElementLocated(By.tagName("img")));

    // Switch back to document context
    driver_.switchTo().defaultContent();
}

From source file:org.rstudio.studio.selenium.RConsoleInteraction.java

License:Open Source License

@Test
public void testInvokeHelp() {
    ConsoleTestUtils.resumeConsoleInteraction(driver_);
    Actions help = new Actions(driver_);
    help.sendKeys(Keys.ESCAPE + "?lapply" + Keys.ENTER);
    help.perform();//from  ww  w . java2  s  .  c om

    // Wait for the Help window to activate
    final WebElement helpWindow = (new WebDriverWait(driver_, 5)).until(
            ExpectedConditions.presenceOfElementLocated(By.id(ElementIds.getElementId(ElementIds.HELP_FRAME))));

    // Wait for help to appear in the window
    Assert.assertEquals(helpWindow.getTagName(), "iframe");
    driver_.switchTo().frame(helpWindow);

    (new WebDriverWait(driver_, 5))
            .until(ExpectedConditions.textToBePresentInElement(By.tagName("body"), "lapply"));

    // Switch back to document context
    driver_.switchTo().defaultContent();
}

From source file:org.rstudio.studio.selenium.SourceInteraction.java

License:Open Source License

@Test
public void findAndReplace() {
    createRFile();//from  ww w  .  j  a  va2  s  .co m

    // Type some code into the file
    String preReplaceCode = "foo <- 'bar'";
    Actions a = new Actions(driver_);
    a.sendKeys(preReplaceCode + Keys.ENTER);
    a.perform();

    // Find the ACE editor instance that the code appears in. (CONSIDER: 
    // This is not the best way to find the code editor instance.)
    WebElement editor = null;
    List<WebElement> editors = driver_.findElements(By.className("ace_content"));
    for (WebElement e : editors) {
        if (e.getText().contains(preReplaceCode)) {
            editor = e;
            break;
        }
    }
    Assert.assertNotNull(editor);

    // Invoke find and replace
    WebElement findMenuEntry = MenuNavigator.getMenuItem(driver_, "Edit", "Find...");
    findMenuEntry.click();

    // Wait for the find and replace panel to come up
    (new WebDriverWait(driver_, 2)).until(ExpectedConditions
            .presenceOfElementLocated(By.id(ElementIds.getElementId(ElementIds.FIND_REPLACE_BAR))));

    // Type the text and the text to be replaced (replace 'bar' with 'foo')
    Actions rep = new Actions(driver_);
    rep.sendKeys("bar" + Keys.TAB + "foo" + Keys.ENTER);
    rep.perform();

    DialogTestUtils.respondToModalDialog(driver_, "OK");

    Actions dismiss = new Actions(driver_);
    dismiss.sendKeys(Keys.ESCAPE);
    dismiss.perform();

    // Ensure that the source has been updated
    Assert.assertTrue(editor.getText().contains("foo <- 'foo'"));

    closeUnsavedRFile();
}

From source file:org.testeditor.fixture.web.WebDriverFixture.java

License:Open Source License

/**
 * This method waits explicitly for a WebElement in the DOM-Object until the
 * given timeOut is reached before an Exception is thrown.
 * //  w w  w .j  av a 2 s . c  o  m
 * @param elementLocator Locator for Gui-Widget
 * @param locatorType Type of locator for Gui-Widget
 * @param timeOutInSeconds The max timeout in seconds when an element is
 *            expected before a NotFoundException will be thrown.
 * @throws FixtureException Exception occurs when wait until an element is 
 *         found on a Web-Element can not be performed. 
 */
@FixtureMethod
public void waitUntilElementFound(String elementLocator, LocatorStrategy locatorType, int timeOutInSeconds)
        throws FixtureException {
    logger.debug("Waiting max {} seconds until element {} with strategy {} is found", timeOutInSeconds,
            elementLocator, locatorType);
    WebDriverWait webDriverWait = new WebDriverWait(driver, timeOutInSeconds);
    logger.trace("Timeout for WebDriverWait is set to {}.", timeOutInSeconds);
    try {
        webDriverWait.until(ExpectedConditions.presenceOfElementLocated(getBy(elementLocator, locatorType)));
        logger.trace("WebDriverWait executed until element with elementlocator {} found.", elementLocator);
    } catch (TimeoutException e) {
        throw new FixtureException("timeout during wait for element", //
                FixtureException.keyValues("elementLocator", elementLocator, //
                        "locatorType", locatorType.toString(), //
                        "timeout", Long.valueOf(timeOutInSeconds)),
                e);
    }
}

From source file:org.wso2.carbon.emm.integration.test.EMMIntegrationTest.java

License:Open Source License

/**
 * Performs the login operation to emm web-app using Selenium.
 *//*  w  w  w . ja  v a 2 s .c o m*/
protected void loginToEmmWebAppViaWebDriver() {
    webDriver.get(EMMIntegrationTestConstants.EMM_CONSOLE_HTTP_ENDPOINT);
    webDriverWait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(.,'Sign in')]")));
    webDriver.findElement(By.xpath("//input[@name='username']")).sendKeys("admin");
    webDriver.findElement(By.xpath("//input[@name='password']")).sendKeys("admin");
    webDriver.findElement(By.xpath("//button[contains(.,'Sign in')]")).click();
    webDriverWait.until(
            ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(.,'Devices By Ownership')]")));
}

From source file:org.wso2.carbon.emm.integration.test.EMMIntegrationTest.java

License:Open Source License

/**
 * Performs the logout operation from emm web-app using Selenium.
 *//*from w w  w.  j  ava 2 s .  c o  m*/
protected void logoutFromEmmWebAppViaWebDriver() {
    webDriver.findElement(By.xpath("//a[contains(.,'Welcome Admin')]")).click();
    webDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[contains(.,'Logout')]")));
    webDriver.findElement(By.xpath("//a[contains(.,'Logout')]")).click();
    webDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(.,'Sign in')]")));
}