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.apache.archiva.web.test.ArchivaAdminTest.java

License:Apache License

@Test
public void testInitialRepositories() {
    WebDriverWait wait = new WebDriverWait(getWebDriver(), 20);
    WebElement el;// w w w. j ava 2  s  .com
    el = wait.until(ExpectedConditions.elementToBeClickable(By.id("menu-repositories-list-a")));
    tryClick(el,
            ExpectedConditions.presenceOfElementLocated(
                    By.xpath("//table[@id='managed-repositories-table']//td[contains(text(),'internal')]")),
            "Managed Repositories not activated");
    wait.until(ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//table[@id='managed-repositories-table']//td[contains(text(),'snapshots')]")));
    el = wait.until(
            ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#remote-repositories-content']")));
    tryClick(el,
            ExpectedConditions.visibilityOfElementLocated(
                    By.xpath("//table[@id='remote-repositories-table']//td[contains(text(),'central')]")),
            "Remote Repositories View not available");

}

From source file:org.apache.archiva.web.test.parent.AbstractSeleniumTest.java

License:Apache License

public void initializeArchiva(String baseUrl, String browser, int maxWaitTimeInMs, String seleniumHost,
        int seleniumPort, boolean remoteSelenium) throws Exception {

    open(baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs, remoteSelenium);
    loadPage(baseUrl, 30);//from ww w  . j a  v  a 2 s.co m
    WebDriverWait wait = new WebDriverWait(getWebDriver(), 30);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("topbar-menu")));

    wait = new WebDriverWait(getWebDriver(), 20);
    Boolean found = wait.until(
            ExpectedConditions.or(ExpectedConditions.visibilityOfElementLocated(By.id("create-admin-link-a")),
                    ExpectedConditions.visibilityOfElementLocated(By.id("login-link-a"))));
    if (found) {

        WebElement adminLink = getWebDriver().findElement(By.id("create-admin-link-a"));
        WebElement loginLink = getWebDriver().findElement(By.id("login-link-a"));

        // if not admin user created create one
        if (adminLink != null && adminLink.isDisplayed()) {

            Assert.assertFalse(isElementVisible("login-link-a"));
            Assert.assertFalse(isElementVisible("register-link-a"));
            // skygo need to set to true for passing is that work as expected ?
            adminLink.click();
            wait = new WebDriverWait(getWebDriver(), 10);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user-create")));
            assertCreateAdmin();
            String fullname = getProperty("ADMIN_FULLNAME");
            String username = getAdminUsername();
            String mail = getProperty("ADMIN_EMAIL");
            String password = getProperty("ADMIN_PASSWORD");
            submitAdminData(fullname, mail, password);
            assertUserLoggedIn(username);
            clickLinkWithLocator("logout-link-a", false);
        } else if (loginLink != null && loginLink.isDisplayed()) {
            Assert.assertTrue(isElementVisible("login-link-a"));
            Assert.assertTrue(isElementVisible("register-link-a"));
            login(getAdminUsername(), getAdminPassword());
        }
    }

}

From source file:org.apache.archiva.web.test.parent.AbstractSeleniumTest.java

License:Apache License

public void goToLoginPage() {
    logger.info("Goto login page");
    loadPage(baseUrl, 30);/*from   w  w w .j av  a 2s  .  co  m*/
    WebDriverWait wait = new WebDriverWait(getWebDriver(), 30);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.id("topbar-menu")));
    wait.until(ExpectedConditions.or(ExpectedConditions.visibilityOfElementLocated(By.id("logout-link")),
            ExpectedConditions.visibilityOfElementLocated(By.id("login-link-a"))));

    // are we already logged in ?
    if (isElementVisible("logout-link")) //isElementPresent( "logoutLink" ) )
    {
        logger.info("Logging out ");
        // so logout
        clickLinkWithLocator("logout-link-a", false);
    }
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login-link-a")));
    clickLinkWithLocator("login-link-a", false);
    // This is a workaround for bug with HTMLUnit. The display attribute of the
    // login dialog is not changed via the click.
    // TODO: Check after changing jquery, bootstrap or htmlunit version
    if (getWebDriver() instanceof HtmlUnitDriver) {
        ((JavascriptExecutor) getWebDriver()).executeScript("$('#modal-login').show();");
    }
    // END OF WORKAROUND
    wait = new WebDriverWait(getWebDriver(), 20);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("modal-login")));
    assertLoginModal();
}

From source file:org.apache.archiva.web.test.RepositoryAdminTest.java

License:Apache License

@Test
public void testManagedRepository() {
    // login( getAdminUsername(), getAdminPassword() );
    WebDriverWait wait = new WebDriverWait(getWebDriver(), 20);
    WebElement el;/* www.  ja va  2s . c o  m*/
    el = wait.until(ExpectedConditions.elementToBeClickable(By.id("menu-repositories-list-a")));
    tryClick(el, ExpectedConditions.presenceOfElementLocated(By.id("managed-repositories-view-a")),
            "Managed Repositories not activated");
    el = wait.until(
            ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#remote-repositories-content']")));
    tryClick(el,
            ExpectedConditions.visibilityOfElementLocated(
                    By.xpath("//table[@id='remote-repositories-table']//td[contains(text(),'central')]")),
            "Remote Repositories View not available");
    el = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@href='#remote-repository-edit']")));
    el = tryClick(el, ExpectedConditions.visibilityOfElementLocated(By.id("remote-repository-save-button")),
            "Repository Save Button not available");

    setFieldValue("id", "myrepoid");
    setFieldValue("name", "My repo name");
    setFieldValue("url", "http://www.repo.org");

    el = wait.until(ExpectedConditions.elementToBeClickable(By.id("remote-repository-save-button")));
    Actions actions = new Actions(getWebDriver());
    actions.moveToElement(el);
    actions.perform();
    ((JavascriptExecutor) getWebDriver()).executeScript("arguments[0].scrollIntoView();", el);
    el.click();
    el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repositories-view-a")));
    ((JavascriptExecutor) getWebDriver()).executeScript("arguments[0].scrollIntoView();", el);
    tryClick(By.id("menu-proxy-connectors-list-a"),
            ExpectedConditions
                    .visibilityOfElementLocated(By.id("proxy-connectors-view-tabs-a-network-proxies-grid")),
            "Network proxies not available", 3, 10);
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("main-content"), "Proxy Connectors"));
    // proxy connect
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central"));
    assertTextNotPresent("myrepoid");
    el = wait.until(ExpectedConditions.elementToBeClickable(By.id("proxy-connectors-view-tabs-a-edit")));
    el.click();
    el = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("proxy-connector-btn-save")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("remote-repository-edit-fieldset")));
    // Another hack, don't know why the normal selectValue() does not work here
    ((JavascriptExecutor) getWebDriver()).executeScript("jQuery('#sourceRepoId').css('display','block')");
    Select select = new Select(getWebDriver().findElement(By.xpath(".//select[@id='sourceRepoId']")));
    select.selectByVisibleText("internal");
    // selectValue( "sourceRepoId", "internal", true );
    // Workaround
    // TODO: Check after upgrade of htmlunit, bootstrap or jquery
    // TODO: Check whats wrong here
    ((JavascriptExecutor) getWebDriver()).executeScript("$('#targetRepoId').show();");
    // End of Workaround
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("targetRepoId")));
    selectValue("targetRepoId", "myrepoid");
    el.click();
    wait.until(
            ExpectedConditions.textToBePresentInElementLocated(By.id("user-messages"), "ProxyConnector added"));
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "central"));
    wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("proxy-connectors-view"), "myrepoid"));

    tryClick(By.xpath("//i[contains(@class,'icon-resize-vertical')]//ancestor::a"),
            ExpectedConditions.visibilityOfAllElementsLocatedBy(By.id("proxy-connector-edit-order-div")),
            "Edit order view not visible", 3, 10);
    // clickLinkWithXPath( "//i[contains(@class,'icon-resize-vertical')]//ancestor::a");
    // This is needed here for HTMLUnit Tests. Currently do not know why, wait is not working for the
    // list entries down
    // waitPage();
    // el = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("proxy-connector-edit-order-div")));
    assertTextPresent("internal");
    List<WebElement> repos = wait.until(ExpectedConditions
            .numberOfElementsToBe(By.xpath("//div[@id='proxy-connector-edit-order-div']/div"), 2));
    Assert.assertTrue("First repo is myrepo", repos.get(0).getText().contains("myrepoid"));
    Assert.assertTrue("Second repo is central", repos.get(1).getText().contains("central"));

    // works until this point
    /*getSelenium().mouseDown( "xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" );
    getSelenium().mouseMove( "xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" );
    getSelenium().mouseUp( "xpath=//div[@id='proxy-connector-edit-order-div']/div[last()]" );
    Assert.assertTrue( "Second repo is myrepo", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ).contains( "myrepoid" ));
    Assert.assertTrue( "First repo is central", getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ).contains( "central" ));
    */
}

From source file:org.apache.deltaspike.test.jsf.impl.message.JsfMessageTest.java

License:Apache License

@Test
@RunAsClient/*from  w  w w  .ja  v  a  2 s.  c om*/
public void testEnglishMessages() throws Exception {
    driver.get(new URL(contextPath, "page.xhtml").toString());

    //X comment this in if you like to debug the server
    //X I've already reported ARQGRA-213 for it
    //X System.out.println("contextpath= " + contextPath);
    //X Thread.sleep(600000L);

    // check the JSF FacesMessages
    Assert.assertNotNull(ExpectedConditions.presenceOfElementLocated(By.xpath("id('messages')")).apply(driver));

    Assert.assertTrue(ExpectedConditions
            .textToBePresentInElement(By.xpath("id('messages')/ul/li[1]"), "message with details warnInfo!")
            .apply(driver));

    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.xpath("id('messages')/ul/li[2]"),
            "message without detail but parameter errorInfo.").apply(driver));

    Assert.assertTrue(ExpectedConditions
            .textToBePresentInElement(By.xpath("id('messages')/ul/li[3]"), "a simple message without a param.")
            .apply(driver));

    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.xpath("id('messages')/ul/li[4]"),
            "simple message with a string param fatalInfo.").apply(driver));

    // check the free message usage
    Assert.assertTrue(ExpectedConditions
            .textToBePresentInElement(By.id("test:valueOutput"), "a simple message without a param.")
            .apply(driver));

    // and also the usage via direct EL invocation
    Assert.assertTrue(ExpectedConditions
            .textToBePresentInElement(By.id("test:elOutput"), "a simple message without a param.")
            .apply(driver));
    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.id("test:elOutputWithParam"),
            "simple message with a string param hiho.").apply(driver));
}

From source file:org.apache.deltaspike.test.jsf.impl.message.JsfMessageTest.java

License:Apache License

@Test
@RunAsClient//from w  ww.  j a v a 2  s .c  o m
public void testGermanMessages() throws Exception {
    driver.get(new URL(contextPath, "page.xhtml?lang=de").toString());

    // check the JSF FacesMessages
    Assert.assertNotNull(ExpectedConditions.presenceOfElementLocated(By.xpath("id('messages')")).apply(driver));

    Assert.assertTrue(ExpectedConditions
            .textToBePresentInElement(By.xpath("id('messages')/ul/li[1]"), "Nachricht mit Details warnInfo!")
            .apply(driver));

    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.xpath("id('messages')/ul/li[2]"),
            "Nachricht ohne Details aber mit Parameter errorInfo.").apply(driver));

    Assert.assertTrue(ExpectedConditions
            .textToBePresentInElement(By.xpath("id('messages')/ul/li[3]"), "Einfache Nachricht ohne Parameter.")
            .apply(driver));

    Assert.assertTrue(ExpectedConditions.textToBePresentInElement(By.xpath("id('messages')/ul/li[4]"),
            "Einfache Nachricht mit String Parameter fatalInfo.").apply(driver));

    // check the free message usage
    Assert.assertTrue(ExpectedConditions
            .textToBePresentInElement(By.id("test:valueOutput"), "Einfache Nachricht ohne Parameter.")
            .apply(driver));
}

From source file:org.apache.nutch.protocol.interactiveselenium.ListImageHandler.java

License:Apache License

public void processDriver(WebDriver driver) {
    System.out.println("=========== Into Handler_vci_classifieds ==========");
    //Get the current page URL and store the value in variable 'url'
    String url = driver.getCurrentUrl();

    //Print the value of variable in the console
    System.out.println("[ListImageHandler][processDriver] The current URL is: " + url);

    //Load a new page in the current browser windows
    driver.get(url);/*from   w w  w  . jav a  2 s.  c  o  m*/

    // form-input structure for search bar
    // WebElement form = driver.findElement(By.tagName("form"));
    // List<WebElement> inputs = null;
    // if (form != null) {
    //     inputs = form.findElements(By.tagName("input"));
    //     for (WebElement elem : inputs) {
    //         if (elem.isDisplayed()) {
    //             elem.clear();
    //             elem.sendKeys("gun\n");
    //             System.out.println("[ListImageHandler][processDriver] Submit keyword \"gun\"");
    //             //form.submit();
    //             break;
    //         }
    //     }
    // }

    // direct input html tag for search bar
    ArrayList<String> possibleName = new ArrayList<String>();
    possibleName.add("q");
    possibleName.add("searchtext");
    possibleName.add("txtSearch");

    WebElement element;
    if (inputs == null) {
        for (int i = 0; i < possibleName.size(); i++) {
            element = driver.findElement(By.name(possibleName.get(i)));
            if (element != null) {
                // send with "\n" == submit
                element.sendKeys("gun\n");
                //element.sendKeys("gun");
                //form.submit();
                System.out.println("[ListImageHandler][processDriver] Submit keyword \"gun\"");
                break;
            }
        }

    }

    // wait for finsih loading webpage, hard code timer
    try {
        System.out.println("[ListImageHandler][processDriver] before sleep");
        Thread.sleep(2000);
        System.out.println("[ListImageHandler][processDriver] after sleep");

    } catch (Exception e) {
        System.out.println("[ListImageHandler][processDriver] Exception caught");
    }

    // find all image element
    List<WebElement> findElements = driver.findElements(By.xpath("//img"));
    if (url.equals("http://www.vci-classifieds.com/")) {
        WebElement myDynamicElement = (new WebDriverWait(driver, 10))
                .until(ExpectedConditions.presenceOfElementLocated(By.id("searchlist")));
        findElements = driver.findElements(By.xpath(".//*[@id='searchlist']/center/table/tbody/tr/td/img"));
    }
    System.out.println("[ListImageHandler][processDriver] total Results Found: " + findElements.size());

    // show all the links of image
    for (WebElement elem : findElements) {
        System.out.println(elem.getAttribute("src"));
        // System.out.println(elem.toString());
    }
    System.out.println("[ListImageHandler][processDriver] " + findElements.size() + " results shown");

    // log outlinks to /tmp/outlinks
    List<WebElement> findOutlinks = driver.findElements(By.xpath("//a"));
    try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("/tmp/outlinks", true)))) {
        // this are all the links you like to visit
        int count = 0;
        for (WebElement elem : findOutlinks) {
            out.println(elem.getAttribute("href"));
            count++;
        }
        System.out.println("[ListImageHandler][processDriver] total Outlinks Logged: " + count);
    } catch (IOException e) {
        System.err.println(e);
    }

    // driver.close();
    // System.out.println("[ListImageHandler][processDriver] Close Driver");
}

From source file:org.apache.syncope.fit.console.reference.AbstractITCase.java

License:Apache License

@Before
public void setUp() throws Exception {
    seleniumDriver = new FirefoxDriver();
    seleniumDriver.get(BASE_URL);
    wait = new WebDriverWait(seleniumDriver, 10);

    WebElement element = seleniumDriver.findElement(By.name("userId"));
    element.sendKeys(ADMIN);// w  w  w  .j a v a2  s .  co  m
    element = seleniumDriver.findElement(By.name("password"));
    element.sendKeys(PASSWORD);
    seleniumDriver.findElement(By.name("p::submit")).click();

    (new WebDriverWait(seleniumDriver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//img[@alt='Logout']")));
}

From source file:org.apache.syncope.fit.console.reference.AccessITCase.java

License:Apache License

@Test
public void clickAround() {
    seleniumDriver.findElement(By.xpath("//img[@alt=\"Schema\"]")).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='tabs']/ul/li[2]/a")));

    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[2]/a")).click();

    wait.until(ExpectedConditions/*from   w  w w.j a  va 2  s .c o m*/
            .presenceOfElementLocated(By.xpath("//div[@id='uschema']/div/div/span/ul/li[2]/a")));

    seleniumDriver.findElement(By.xpath("//div[@id='uschema']/div/div/span/ul/li[2]/a")).click();
    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[3]/a")).click();
    seleniumDriver.findElement(By.xpath("//div[@id='mschema']/div/div/span/ul/li[2]/a")).click();
    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[4]/a")).click();

    seleniumDriver.findElement(By.xpath("//div[@id='gschema']/div/div/span/ul/li[2]/a")).click();

    seleniumDriver.findElement(By.xpath("//img[@alt=\"Users\"]")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[3]/ul/li[2]/a/span")));
    seleniumDriver.findElement(By.xpath("//div[3]/ul/li[2]/a/span")).click();

    seleniumDriver.findElement(By.xpath("//img[@alt=\"Groups\"]")).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//img[@alt=\"Resources\"]")));

    seleniumDriver.findElement(By.xpath("//img[@alt=\"Resources\"]")).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//img[@alt=\"TODO\"]")));

    seleniumDriver.findElement(By.xpath("//img[@alt=\"TODO\"]")).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//img[@alt=\"Reports\"]")));

    seleniumDriver.findElement(By.xpath("//img[@alt=\"Reports\"]")).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//img[@alt=\"Configuration\"]")));

    seleniumDriver.findElement(By.xpath("//img[@alt=\"Configuration\"]")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='tabs']/ul/li[2]/a/span")));

    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[3]/a/span")).click();

    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[3]/a/span")).click();
    seleniumDriver.findElement(By.xpath("//img[@alt=\"Tasks\"]")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='tabs']/ul/li[2]/a/span")));

    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[2]/a/span")).click();
    seleniumDriver.findElement(By.xpath("//img[@alt=\"Tasks\"]")).click();
    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[4]/a/span")).click();
    seleniumDriver.findElement(By.xpath("//div[@id='tabs']/ul/li[5]/a/span")).click();
}

From source file:org.apache.syncope.fit.console.reference.ConfigurationITCase.java

License:Apache License

@Test
public void editParameters() {
    seleniumDriver.findElement(By.xpath("//img[@alt=\"Configuration\"]")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='tabs']")));
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//img[@title='Parameters']")));

    seleniumDriver.findElement(By.xpath("//img[@title='Parameters']/ancestor::a")).click();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//iframe")));
    seleniumDriver.switchTo().frame(0);/*from www .ja va2  s  . c o  m*/

    seleniumDriver
            .findElement(By.xpath("//span[contains(text(), 'log.lastlogindate')]/../../div[2]/span/input"))
            .click();
    seleniumDriver.findElement(By.xpath("//div[2]/form/div[3]/input[@type='submit']")).click();

    seleniumDriver.switchTo().defaultContent();

    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='tabs']")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("feedback")));
    assertTrue(seleniumDriver.findElement(By.tagName("body")).getText()
            .contains("Operation executed successfully"));
}