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.glowroot.agent.webdriver.tests.config.GaugeConfigPage.java

License:Apache License

private void clickTypeAheadItem(String label, final String text) {
    final By xpath = xpath("//div[label[normalize-space()='" + label + "']]//ul/li/a");
    new WebDriverWait(driver, 30).until(new Predicate<WebDriver>() {
        @Override/* ww w. j  ava2 s.c  o m*/
        public boolean apply(WebDriver driver) {
            for (WebElement element : driver.findElements(xpath)) {
                if (element.getText().equals(text)) {
                    try {
                        element.click();
                        return true;
                    } catch (StaleElementReferenceException e) {
                        // type ahead was catching up and replaced li with a new one
                        return false;
                    }
                }
            }
            return false;
        }
    });
}

From source file:org.glowroot.agent.webdriver.tests.GlobalNavbar.java

License:Apache License

public static WebElement getNavbarLink(final WebDriver driver, final By by) {
    return new WebDriverWait(driver, 30).until(new Function<WebDriver, WebElement>() {
        @Override/*from w w w  .ja  v a2 s .  c o m*/
        public WebElement apply(WebDriver driver) {
            List<WebElement> elements = driver.findElements(by);
            if (elements.isEmpty()) {
                openNavbar();
                return null;
            }
            WebElement element = elements.get(0);
            if (!element.isDisplayed()) {
                openNavbar();
                return null;
            }
            List<WebElement> overlayElements = driver.findElements(By.className("gt-panel-overlay"));
            for (WebElement overlayElement : overlayElements) {
                if (overlayElement.isDisplayed()) {
                    return null;
                }
            }
            return element;
        }

        private void openNavbar() {
            List<WebElement> navbarToggleElements = driver.findElements(By.cssSelector("button.navbar-toggle"));
            if (!navbarToggleElements.isEmpty() && navbarToggleElements.get(0).isDisplayed()) {
                navbarToggleElements.get(0).click();
            }
        }
    });
}

From source file:org.glowroot.agent.webdriver.tests.Utils.java

License:Apache License

public static WebElement withWait(WebDriver driver, final SearchContext context, final By by) {
    return new WebDriverWait(driver, 30).until(new Function<WebDriver, WebElement>() {
        @Override//from  w  w w.ja va 2  s .  c  o m
        public WebElement apply(WebDriver driver) {
            List<WebElement> elements = context.findElements(by);
            if (elements.isEmpty()) {
                return null;
            }
            WebElement element = elements.get(0);
            if (!element.isDisplayed()) {
                return null;
            }
            List<WebElement> overlayElements = driver.findElements(By.className("gt-panel-overlay"));
            for (WebElement overlayElement : overlayElements) {
                if (overlayElement.isDisplayed()) {
                    return null;
                }
            }
            return element;
        }
    });
}

From source file:org.glowroot.tests.config.GaugeConfigPage.java

License:Apache License

private void clickTypeAheadItem(String label, final String text) {
    final By xpath = xpath("//div[label[normalize-space()='" + label + "']]//ul/li/a");
    new WebDriverWait(driver, 30).until(new Function<WebDriver, Boolean>() {
        @Override//from w w w  .  j a va2 s . c o  m
        public Boolean apply(WebDriver driver) {
            for (WebElement element : driver.findElements(xpath)) {
                if (element.getText().equals(text)) {
                    try {
                        element.click();
                        return true;
                    } catch (StaleElementReferenceException e) {
                        // type ahead was catching up and replaced li with a new one
                        return false;
                    }
                }
            }
            return false;
        }
    });
}

From source file:org.glowroot.tests.GlobalNavbar.java

License:Apache License

public static WebElement getNavbarLink(final WebDriver driver, final By by) {
    return new WebDriverWait(driver, 30).until(new Function<WebDriver, WebElement>() {
        @Override//  www  .  jav a  2  s .  c o  m
        public WebElement apply(WebDriver driver) {
            List<WebElement> elements = driver.findElements(by);
            if (elements.isEmpty()) {
                openNavbar();
                return null;
            }
            WebElement element = elements.get(0);
            try {
                if (!element.isDisplayed()) {
                    openNavbar();
                    return null;
                }
            } catch (StaleElementReferenceException e) {
                // dom was updated in between findElements() and isDisplayed()
                return null;
            }
            List<WebElement> overlayElements = driver.findElements(By.className("gt-panel-overlay"));
            for (WebElement overlayElement : overlayElements) {
                try {
                    if (overlayElement.isDisplayed()) {
                        return null;
                    }
                } catch (StaleElementReferenceException e) {
                    // dom was updated in between findElements() and isDisplayed()
                    return null;
                }
            }
            return element;
        }

        private void openNavbar() {
            List<WebElement> navbarToggleElements = driver.findElements(By.cssSelector("button.navbar-toggle"));
            if (!navbarToggleElements.isEmpty() && navbarToggleElements.get(0).isDisplayed()) {
                navbarToggleElements.get(0).click();
            }
        }
    });
}

From source file:org.glowroot.tests.util.Utils.java

License:Apache License

public static WebElement withWait(WebDriver driver, final SearchContext context, final By by) {
    return new WebDriverWait(driver, 30).until(new Function<WebDriver, WebElement>() {
        @Override//from  w  w  w .  j  a  va  2  s.c  o m
        public WebElement apply(WebDriver driver) {
            List<WebElement> elements = context.findElements(by);
            if (elements.isEmpty()) {
                return null;
            }
            WebElement foundElement = null;
            for (WebElement element : elements) {
                try {
                    if (element.isDisplayed()) {
                        foundElement = element;
                        break;
                    }
                } catch (StaleElementReferenceException e) {
                    // dom was updated in between findElements() and isDisplayed()
                }
            }
            if (foundElement == null) {
                return null;
            }
            List<WebElement> overlayElements = driver.findElements(By.className("gt-panel-overlay"));
            for (WebElement overlayElement : overlayElements) {
                try {
                    if (overlayElement.isDisplayed()) {
                        return null;
                    }
                } catch (StaleElementReferenceException e) {
                    // dom was updated in between findElements() and isDisplayed()
                    return null;
                }
            }
            return foundElement;
        }
    });
}

From source file:org.jboss.arquillian.graphene.context.TestGrapheneProxyHandler.java

License:Open Source License

@Test
public void test_webDriver_methods_which_should_return_proxy() {
    IsProxyable isProxyable = new IsProxyable();

    // when//from  w w w  .  j a  va 2 s . c  o  m
    WebDriver driver = Mockito.mock(WebDriver.class, isProxyable);
    Options options = mock(Options.class, isProxyable);
    TargetLocator targetLocator = mock(TargetLocator.class, isProxyable);
    ImeHandler ime = mock(ImeHandler.class, isProxyable);
    Timeouts timeouts = mock(Timeouts.class, isProxyable);

    // then
    try {
        driver.manage();
        driver.navigate();
        driver.switchTo();
        driver.findElement(By.className(""));
        driver.findElements(By.className(""));
        driver.getWindowHandles();

        options.ime();
        options.logs();
        options.timeouts();
        options.window();
        options.getCookies();

        targetLocator.activeElement();
        targetLocator.alert();
        targetLocator.defaultContent();
        targetLocator.frame(0);
        targetLocator.frame("name");
        targetLocator.frame(mock(WebElement.class));
        targetLocator.window("name");

        ime.getAvailableEngines();

        timeouts.implicitlyWait(1L, TimeUnit.MICROSECONDS);
        timeouts.setScriptTimeout(1L, TimeUnit.MICROSECONDS);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    assertEquals(Arrays.asList(), isProxyable.getViolations());
}

From source file:org.jenkinsci.test.acceptance.selenium.SanityChecker.java

License:Open Source License

private void checkSanity(WebDriver driver) {
    if (isFastPath(driver))
        return;//from   ww w  . j a  v a 2  s  . co  m

    // Exception
    List<WebElement> elements = driver.findElements(SPECIFIER);
    if (!elements.isEmpty()) {
        String trace = elements.get(0).getText();

        if (trace.contains("<j:forEach> java.util.ConcurrentModificationException")) {
            // Do not report JENKINS-22553 as it is recoverable and fails dozens of tests
            return;
        }

        throw new AssertionError("Jenkins error detected:\n" + trace);
    }

    // POST required
    WebElement postForm = driver.findElement(By.cssSelector("form > input[value='Try POSTing']"));
    if (postForm != null)
        throw new AssertionError("Post required at " + driver.getCurrentUrl());

}

From source file:org.jitsi.meet.test.ActiveSpeakerTest.java

License:Apache License

/**
 * Asserts that the number of small videos with the dominant speaker
 * indicator displayed equals 1.// www. jav  a  2 s  .  c o  m
 * @param driver the participant to check
 */
private void assertOneDominantSpeaker(WebDriver driver) {
    List<WebElement> dominantSpeakerIndicators = driver
            .findElements(By.xpath("//span[contains(@id,'dominantspeakerindicator')]"));

    int speakers = 0;
    for (WebElement el : dominantSpeakerIndicators) {
        if (el.isDisplayed())
            speakers++;
    }

    assertEquals("Wrong number of dominant speaker indicators.", 1, speakers);
}

From source file:org.jitsi.meet.test.JibriTest.java

License:Apache License

/**
 * Checks if the recording button exists.
 *///from w  ww  .jav  a 2 s.  c o  m
public void checkJibriEnabled() {
    System.err.println("Start checkJibriEnabled.");
    WebDriver owner = ConferenceFixture.getOwner();
    List<WebElement> elems = owner.findElements(By.xpath("//a[@class='button fa " + "fa-play-circle']"));

    assertFalse("Jibri button is missing", elems.isEmpty());

}