Example usage for org.openqa.selenium WebDriver findElements

List of usage examples for org.openqa.selenium WebDriver findElements

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver findElements.

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current page using the given mechanism.

Usage

From source file:org.opennms.smoketest.IndexPageIT.java

License:Open Source License

@Test
public void verifyStatusMap() {
    // In order to have anything show up, we have to create a node with long/lat information first
    // A interface and service which does not exist is used, in order to provoke an alarm beeing sent by opennms
    // to have a status >= Warning
    // INITIALIZE
    LOG.info("Initializing foreign source with no detectors");
    String foreignSourceXML = "<foreign-source name=\"" + OpenNMSSeleniumTestCase.REQUISITION_NAME + "\">\n"
            + "<scan-interval>1d</scan-interval>\n" + "<detectors/>\n" + "<policies/>\n" + "</foreign-source>";
    createForeignSource(REQUISITION_NAME, foreignSourceXML);
    LOG.info("Initializing node with  source with no detectors");
    String requisitionXML = "<model-import foreign-source=\"" + OpenNMSSeleniumTestCase.REQUISITION_NAME + "\">"
            + "   <node foreign-id=\"tests\" node-label=\"192.0.2.1\">"
            + "       <interface ip-addr=\"192.0.2.1\" status=\"1\" snmp-primary=\"N\">"
            + "           <monitored-service service-name=\"ICMP\"/>" + "       </interface>"
            + "       <asset name=\"longitude\" value=\"-0.075949\"/>"
            + "       <asset name=\"latitude\" value=\"51.508112\"/>" + "   </node>" + "</model-import>";
    createRequisition(REQUISITION_NAME, requisitionXML, 1);

    // try every 5 seconds, for 120 seconds, until the service on 127.0.0.2 has been detected as "down", or fail afterwards
    try {//w  w  w . j a  v  a 2  s.  c om
        setImplicitWait(5, TimeUnit.SECONDS);
        new WebDriverWait(m_driver, 120).until(new Predicate<WebDriver>() {
            @Override
            public boolean apply(@Nullable WebDriver input) {
                // refresh page
                input.get(getBaseUrl() + "opennms/index.jsp");

                // Wait until we have markers
                List<WebElement> markerElements = input
                        .findElements(By.xpath("//*[contains(@class, 'leaflet-marker-icon')]"));
                return !markerElements.isEmpty();
            }
        });
    } finally {
        setImplicitWait();
    }
}

From source file:org.openqa.grid.e2e.misc.GridViaCommandLineTest.java

License:Apache License

@Test
public void testRegisterNodeToHub() throws Exception {
    String[] hubArgs = { "-role", "hub" };
    GridLauncherV3.main(hubArgs);/*w  ww .j a va  2  s  . c  o m*/
    UrlChecker urlChecker = new UrlChecker();
    urlChecker.waitUntilAvailable(10, TimeUnit.SECONDS, new URL("http://localhost:4444/grid/console"));

    String[] nodeArgs = { "-role", "node", "-hub", "http://localhost:4444", "-browser",
            "browserName=chrome,maxInstances=1" };
    GridLauncherV3.main(nodeArgs);
    urlChecker.waitUntilAvailable(100, TimeUnit.SECONDS, new URL("http://localhost:5555/wd/hub/status"));

    WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),
            DesiredCapabilities.chrome());

    try {
        driver.get("http://localhost:4444/grid/console");
        Assert.assertEquals("Should only have one chrome registered to the hub", 1,
                driver.findElements(By.cssSelector("img[src$='chrome.png']")).size());
    } finally {
        try {
            driver.quit();
        } catch (Exception e) {
        }
    }

}

From source file:org.orcid.integration.blackbox.api.v2.rc1.BlackBoxBase.java

License:Open Source License

public static void revokeApplicationsAccess(String... clientIdsParam) {
    // Nothing to remove
    if (clientIdsParam == null) {
        return;/*from   w  w  w . j a v  a2  s.  c  om*/
    }
    List<String> clientIds = new ArrayList<String>();
    for (String clientId : clientIdsParam) {
        if (!PojoUtil.isEmpty(clientId)) {
            clientIds.add(clientId);
        }
    }

    String userName = System.getProperty("org.orcid.web.testUser1.username");
    String password = System.getProperty("org.orcid.web.testUser1.password");
    String baseUrl = "https://localhost:8443/orcid-web";
    if (!PojoUtil.isEmpty(System.getProperty("org.orcid.web.base.url"))) {
        baseUrl = System.getProperty("org.orcid.web.base.url");
    }

    WebDriver webDriver = new FirefoxDriver();

    int timeout = 4;
    webDriver.get(baseUrl + "/userStatus.json?logUserOut=true");
    webDriver.get(baseUrl + "/my-orcid");
    SigninTest.signIn(webDriver, userName, password);

    // Switch to accounts settings page
    By accountSettingsMenuLink = By.id("accountSettingMenuLink");
    (new WebDriverWait(webDriver, timeout))
            .until(ExpectedConditions.presenceOfElementLocated(accountSettingsMenuLink));
    WebElement menuItem = webDriver.findElement(accountSettingsMenuLink);
    menuItem.click();

    try {
        boolean lookAgain = false;
        do {
            // Look for each revoke app button
            By revokeAppBtn = By.id("revokeAppBtn");
            (new WebDriverWait(webDriver, timeout))
                    .until(ExpectedConditions.presenceOfElementLocated(revokeAppBtn));
            List<WebElement> appsToRevoke = webDriver.findElements(revokeAppBtn);
            boolean elementFound = false;
            // Iterate on them and delete the ones created by the specified
            // client id
            for (WebElement appElement : appsToRevoke) {
                String nameAttribute = appElement.getAttribute("name");
                if (clientIds.contains(nameAttribute)) {
                    appElement.click();
                    Thread.sleep(1000);
                    // Wait for the revoke button
                    By confirmRevokeAppBtn = By.id("confirmRevokeAppBtn");
                    (new WebDriverWait(webDriver, timeout))
                            .until(ExpectedConditions.presenceOfElementLocated(confirmRevokeAppBtn));
                    WebElement trash = webDriver.findElement(confirmRevokeAppBtn);
                    trash.click();
                    Thread.sleep(2000);
                    elementFound = true;
                    break;
                }
            }

            if (elementFound) {
                lookAgain = true;
            } else {
                lookAgain = false;
            }
        } while (lookAgain);

    } catch (Exception e) {
        // If it fail is because it couldnt find any other application
    } finally {
        webDriver.get(baseUrl + "/userStatus.json?logUserOut=true");
        webDriver.quit();
    }
}

From source file:org.orcid.integration.blackbox.api.v2.rc2.BlackBoxBase.java

License:Open Source License

public static void revokeApplicationsAccess(String... clientIdsParam) {
    // Nothing to remove
    if (clientIdsParam == null) {
        return;//  w  ww.ja v  a  2s  .c o  m
    }
    List<String> clientIds = new ArrayList<String>();
    for (String clientId : clientIdsParam) {
        if (!PojoUtil.isEmpty(clientId)) {
            clientIds.add(clientId);
        }
    }

    String userName = System.getProperty("org.orcid.web.testUser1.username");
    String password = System.getProperty("org.orcid.web.testUser1.password");
    String baseUrl = "https://localhost:8443/orcid-web";
    if (!PojoUtil.isEmpty(System.getProperty("org.orcid.web.base.url"))) {
        baseUrl = System.getProperty("org.orcid.web.base.url");
    }

    WebDriver webDriver = new FirefoxDriver();

    int timeout = 4;
    webDriver.get(baseUrl + "/userStatus.json?logUserOut=true");
    webDriver.get(baseUrl + "/my-orcid");
    SigninTest.signIn(webDriver, userName, password);

    // Switch to accounts settings page
    By accountSettingsMenuLink = By.id("accountSettingMenuLink");
    (new WebDriverWait(webDriver, timeout))
            .until(ExpectedConditions.presenceOfElementLocated(accountSettingsMenuLink));
    WebElement menuItem = webDriver.findElement(accountSettingsMenuLink);
    menuItem.click();

    try {

        boolean lookAgain = false;

        do {
            // Look for each revoke app button
            By revokeAppBtn = By.id("revokeAppBtn");
            (new WebDriverWait(webDriver, timeout))
                    .until(ExpectedConditions.presenceOfElementLocated(revokeAppBtn));
            List<WebElement> appsToRevoke = webDriver.findElements(revokeAppBtn);
            boolean elementFound = false;
            // Iterate on them and delete the ones created by the specified
            // client id
            for (WebElement appElement : appsToRevoke) {
                String nameAttribute = appElement.getAttribute("name");
                if (clientIds.contains(nameAttribute)) {
                    appElement.click();
                    Thread.sleep(1000);
                    // Wait for the revoke button
                    By confirmRevokeAppBtn = By.id("confirmRevokeAppBtn");
                    (new WebDriverWait(webDriver, timeout))
                            .until(ExpectedConditions.presenceOfElementLocated(confirmRevokeAppBtn));
                    WebElement trash = webDriver.findElement(confirmRevokeAppBtn);
                    trash.click();
                    Thread.sleep(2000);
                    elementFound = true;
                    break;
                }
            }

            if (elementFound) {
                lookAgain = true;
            } else {
                lookAgain = false;
            }

        } while (lookAgain);

    } catch (Exception e) {
        // If it fail is because it couldnt find any other application
    } finally {
        webDriver.get(baseUrl + "/userStatus.json?logUserOut=true");
        webDriver.quit();
    }
}

From source file:org.orcid.integration.blackbox.BlackBoxBase.java

License:Open Source License

public static void revokeApplicationsAccess(String... clientIdsParam) {
    // Nothing to remove
    if (clientIdsParam == null) {
        return;//from w  ww.  ja  v  a 2 s .  c om
    }
    List<String> clientIds = new ArrayList<String>();
    for (String clientId : clientIdsParam) {
        if (!PojoUtil.isEmpty(clientId)) {
            clientIds.add(clientId);
        }
    }

    String userName = System.getProperty("org.orcid.web.testUser1.username");
    String password = System.getProperty("org.orcid.web.testUser1.password");
    String baseUrl = "http://localhost:8080/orcid-web";
    if (!PojoUtil.isEmpty(System.getProperty("org.orcid.web.base.url"))) {
        baseUrl = System.getProperty("org.orcid.web.base.url");
    }

    WebDriver webDriver = new FirefoxDriver();

    int timeout = 4;
    webDriver.get(baseUrl + "/userStatus.json?logUserOut=true");
    webDriver.get(baseUrl + "/my-orcid");
    SigninTest.signIn(webDriver, userName, password);

    // Switch to accounts settings page
    By accountSettingsMenuLink = By.id("accountSettingMenuLink");
    (new WebDriverWait(webDriver, timeout))
            .until(ExpectedConditions.presenceOfElementLocated(accountSettingsMenuLink));
    WebElement menuItem = webDriver.findElement(accountSettingsMenuLink);
    menuItem.click();

    try {

        boolean lookAgain = false;

        do {
            // Look for each revoke app button
            By revokeAppBtn = By.id("revokeAppBtn");
            (new WebDriverWait(webDriver, timeout))
                    .until(ExpectedConditions.presenceOfElementLocated(revokeAppBtn));
            List<WebElement> appsToRevoke = webDriver.findElements(revokeAppBtn);
            boolean elementFound = false;
            // Iterate on them and delete the ones created by the specified
            // client id
            for (WebElement appElement : appsToRevoke) {
                String nameAttribute = appElement.getAttribute("name");
                if (clientIds.contains(nameAttribute)) {
                    appElement.click();
                    Thread.sleep(1000);
                    // Wait for the revoke button
                    By confirmRevokeAppBtn = By.id("confirmRevokeAppBtn");
                    (new WebDriverWait(webDriver, timeout))
                            .until(ExpectedConditions.presenceOfElementLocated(confirmRevokeAppBtn));
                    WebElement trash = webDriver.findElement(confirmRevokeAppBtn);
                    trash.click();
                    Thread.sleep(2000);
                    elementFound = true;
                    break;
                }
            }

            if (elementFound) {
                lookAgain = true;
            } else {
                lookAgain = false;
            }

        } while (lookAgain);

    } catch (Exception e) {
        // If it fail is because it couldnt find any other application
    } finally {
        webDriver.get(baseUrl + "/userStatus.json?logUserOut=true");
        webDriver.quit();
    }
}

From source file:org.orcid.integration.blackbox.web.SigninTest.java

License:Open Source License

public static void dismissVerifyEmailModal(WebDriver webDriver) {
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    List<WebElement> weList = webDriver.findElements(By.xpath("//div[@ng-controller='VerifyEmailCtrl']"));
    if (weList.size() > 0) {// we need to wait for the color box to appear
        wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(
                By.xpath("//div[@ng-controller='VerifyEmailCtrl' and @orcid-loading='false']")));
        ((JavascriptExecutor) webDriver).executeScript("$.colorbox.close();");
        colorBoxIsClosed(wait);//from w w w .  jav a2s  .c o  m
    }
}

From source file:org.orcid.integration.blackbox.web.works.AddWorksTest.java

License:Open Source License

public static void deleteAllByWorkName(String workName, WebDriver webDriver) {
    WebDriverWait wait = new WebDriverWait(webDriver, 10);
    waitWorksLoaded(wait);// w ww  .  j a v  a  2 s . c  om
    List<WebElement> wList = webDriver
            .findElements(By.xpath("//*[@orcid-put-code and descendant::span[text() = '" + workName + "']]"));
    if (wList.size() > 0)
        for (WebElement we : wList) {
            String putCode = we.getAttribute("orcid-put-code");
            putCode = "" + putCode;
            String deleteJsStr = "angular.element('*[ng-app]').injector().get('worksSrvc').deleteWork('"
                    + putCode + "');";
            ((JavascriptExecutor) webDriver).executeScript(deleteJsStr);
            waitWorksLoaded(wait);
        }
    wait.until(
            ExpectedConditions.not(ExpectedConditions.presenceOfAllElementsLocatedBy(byWorkTitle(workName))));
    assertTrue(0 == webDriver.findElements(byWorkTitle(workName)).size());
}

From source file:org.orcid.integration.blackbox.web.works.AddWorksTest.java

License:Open Source License

public static String firstPutCodeByTitle(String title, WebDriver webDriver) {
    List<WebElement> wList = webDriver
            .findElements(By.xpath("//*[@orcid-put-code and descendant::span[text() = '" + title + "']]"));
    return wList.get(0).getAttribute("orcid-put-code");
}

From source file:org.paxml.selenium.webdriver.SelectableTag.java

License:Open Source License

/**
 * /* www . java2  s  .  c o  m*/
 * @param canBeEmpty
 * @return never null
 */
public List<WebElement> findElements(Boolean canBeEmpty) {
    WebDriver session = getSession();
    List<WebElement> list;
    if (StringUtils.isNotBlank(javascript)) {

        Object obj = ((JavascriptExecutor) session).executeScript(javascript);
        if (obj instanceof WebElement) {
            list = new ArrayList<WebElement>(1);
            list.add((WebElement) obj);

        } else if (obj instanceof List) {
            list = (List<WebElement>) obj;
        } else {
            throw new RuntimeException("Unknown result from javascript:\r\n" + javascript);
        }

    } else {
        list = session.findElements(myBy());
    }
    boolean allowEmpty = (canBeEmpty == null && allowNotFound) || (canBeEmpty != null && canBeEmpty);
    if (!allowEmpty && list.size() <= 0) {
        throw new RuntimeException("No elements found with selector: " + selector);
    }
    return list;
}

From source file:org.qe4j.web.OpenWebDriverTest.java

License:Open Source License

@Test
public void findElements() throws IOException {
    Properties properties = getProperties();
    WebDriver driver = new OpenWebDriver(properties);
    driver.get(URL);/*from   ww  w . ja  va2  s . co m*/
    List<WebElement> fields = driver.findElements(By.tagName("div"));
    Assert.assertEquals(fields.size(), 2, "found multiple divs");
}