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.nuxeo.ftest.cap.ITRichfileUploadTest.java

License:Apache License

protected void removeFirstUploadedItem() {
    Locator.waitUntilGivenFunctionIgnoring(new Function<WebDriver, Boolean>() {
        @Override// ww w.j  a  v a  2s.c  om
        public Boolean apply(WebDriver driver) {
            try {
                driver.switchTo().alert().dismiss();
                log.warn("Modal dialog present");
            } catch (NoAlertPresentException e) {
                // Expected
            }
            List<WebElement> uploadedFiles = driver.findElements(By.xpath(NX_UPLOADED_FILES_XPATH));
            Locator.waitUntilEnabledAndClick(uploadedFiles.get(0).findElements(By.tagName("a")).get(0));
            Alert confirmRemove = driver.switchTo().alert();
            confirmRemove.accept();
            return true;
        }
    }, StaleElementReferenceException.class);
}

From source file:org.nuxeo.ftest.cap.ITSafeEditTest.java

License:Apache License

private void checkSafeEditRestoreProvided() {
    // We must find the status message asking if we want to restore
    // previous unchanged data, and make sure it is visible
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(5, TimeUnit.SECONDS)
            .pollingEvery(100, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class);
    wait.until(new Function<WebDriver, WebElement>() {
        @Override/* w w  w . ja  va 2s .  com*/
        public WebElement apply(WebDriver driver) {
            List<WebElement> elts = driver
                    .findElements(By.xpath("//div[contains(.,'A draft of this document has been saved')]"));
            if (!elts.isEmpty()) {
                return elts.get(0);
            }
            return null;
        }
    });
}

From source file:org.nuxeo.functionaltests.AbstractTest.java

License:Open Source License

public static List<WebElement> findElementsWithTimeout(final By by) throws NoSuchElementException {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS)
            .pollingEvery(POLLING_FREQUENCY_SECONDS, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
    return wait.until(new Function<WebDriver, List<WebElement>>() {
        public List<WebElement> apply(WebDriver driver) {
            List<WebElement> elements = driver.findElements(by);
            return elements.isEmpty() ? null : elements;
        }/*from www.j  ava  2  s .com*/
    });
}

From source file:org.nuxeo.functionaltests.fragment.GadgetsContainerFragment.java

License:Open Source License

public WebElement waitForGadgetsLoad(final String mandatoryElements) {
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
            .withTimeout(AbstractTest.LOAD_TIMEOUT_SECONDS, TimeUnit.SECONDS).pollingEvery(5, TimeUnit.SECONDS)
            .ignoring(NoSuchElementException.class);
    return wait.until(new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver driver) {
            WebElement container = getElement();
            // iterate through all frames, and ensure opensocial ones are
            // loaded, and expect at least one opensocial frame
            boolean oneFound = false;
            List<WebElement> framesList = driver.findElements(By.xpath("//iframe"));
            if (framesList != null && !framesList.isEmpty()) {
                List<String> mandatory = Arrays.asList(mandatoryElements.split(","));
                for (WebElement frame : framesList) {
                    String frameName = frame.getAttribute("name");
                    if (frameName == null || !frameName.startsWith("open-social")) {
                        continue;
                    }//  w  w  w .  j a  v a2s.c om
                    log.debug(String.format("Found one GWT gadget frame named '%s' ", frameName));
                    oneFound = true;
                    boolean loaded = false;
                    driver.switchTo().defaultContent();
                    driver.switchTo().frame(frame);
                    for (String mand : mandatory) {
                        try {
                            driver.findElement(By.id(mand));
                            loaded = true;
                            log.debug(String.format("Gadget frame '%s' mandatory element '%s' loaded",
                                    frameName, mand));
                        } catch (NoSuchElementException e) {
                            loaded = false;
                            log.debug(String.format(
                                    "Gadget frame '%s' not loaded yet, " + "mandatory element '%s' not found",
                                    frameName, mand));
                            break;
                        }
                    }
                    if (!loaded) {
                        log.debug(String.format("Gadget frame '%s' not loaded yet", frameName));
                        driver.switchTo().defaultContent();
                        return null;
                    }
                    log.debug(String.format("Gadget frame '%s' loaded", frameName));
                    driver.switchTo().defaultContent();
                }
            }
            if (oneFound) {
                return container;
            }
            log.debug("No gadget frame loaded yet");
            return null;
        }
    });
}

From source file:org.nuxeo.functionaltests.Locator.java

License:Apache License

public static List<WebElement> findElementsWithTimeout(final By by) throws NoSuchElementException {
    FluentWait<WebDriver> wait = getFluentWait();
    wait.ignoring(NoSuchElementException.class);
    return wait.until(new Function<WebDriver, List<WebElement>>() {
        @Override/*from   w ww  .  j av  a2 s.com*/
        public List<WebElement> apply(WebDriver driver) {
            List<WebElement> elements = driver.findElements(by);
            return elements.isEmpty() ? null : elements;
        }
    });
}

From source file:org.olat.selenium.page.forum.ForumPage.java

License:Apache License

/**
 * Get the forum from a course element.//from  w  ww .j av a 2s  . co  m
 * 
 * @param browser
 * @return
 */
public static ForumPage getCourseForumPage(WebDriver browser) {
    By forumBy = By.cssSelector("div.o_course_run div.o_forum");
    List<WebElement> forumEl = browser.findElements(forumBy);
    Assert.assertFalse(forumEl.isEmpty());

    By mainBy = By.cssSelector("div.o_course_run");
    WebElement main = browser.findElement(mainBy);
    return Graphene.createPageFragment(ForumPage.class, main);
}

From source file:org.olat.selenium.page.forum.ForumPage.java

License:Apache License

public static ForumPage getGroupForumPage(WebDriver browser) {
    By forumBy = By.cssSelector("div.o_forum");
    List<WebElement> forumEl = browser.findElements(forumBy);
    Assert.assertFalse(forumEl.isEmpty());

    return new ForumPage(browser);
}

From source file:org.olat.selenium.page.graphene.CloseAlertInfoPredicate.java

License:Apache License

@Override
public boolean apply(WebDriver driver) {
    List<WebElement> closeButtons = driver.findElements(alertBy);
    return closeButtons.isEmpty();
}

From source file:org.olat.selenium.page.graphene.OOGraphene.java

License:Apache License

public static final void datetime(Date date, String seleniumCssClass, WebDriver browser) {
    Locale locale = getLocale(browser);
    String dateText = DateFormat.getDateInstance(DateFormat.SHORT, locale).format(date);
    By dateBy = By.cssSelector("div." + seleniumCssClass + " input.o_date_day");
    browser.findElement(dateBy).sendKeys(dateText);

    By timeBy = By.cssSelector("div." + seleniumCssClass + " input.o_date_ms");
    List<WebElement> timeEls = browser.findElements(timeBy);
    Assert.assertNotNull(timeEls);//from ww w  . ja  va2  s  .  c o m
    Assert.assertEquals(2, timeEls.size());

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    int hour = cal.get(Calendar.HOUR_OF_DAY);
    int minute = cal.get(Calendar.MINUTE);
    timeEls.get(0).click();
    timeEls.get(0).clear();
    timeEls.get(0).sendKeys(Integer.toString(hour));
    timeEls.get(1).clear();
    timeEls.get(1).sendKeys(Integer.toString(minute));
}

From source file:org.olat.selenium.page.graphene.OOGraphene.java

License:Apache License

public static final void closeBlueMessageWindow(WebDriver browser) {
    By closeButtonBy = By.cssSelector("div.o_alert_info div.o_sel_info_message i.o_icon.o_icon_close");
    List<WebElement> closeButtons = browser.findElements(closeButtonBy);
    for (WebElement closeButton : closeButtons) {
        if (closeButton.isDisplayed()) {
            try {
                clickCloseButton(closeButton);
            } catch (TimeoutException e) {
                try {
                    clickCloseButton(closeButton);
                } catch (Exception e2) {
                    //
                }//from ww  w . j a  va 2 s .c  om
            }
        }
    }
}