Example usage for org.openqa.selenium.lift.find BaseFinder BaseFinder

List of usage examples for org.openqa.selenium.lift.find BaseFinder BaseFinder

Introduction

In this page you can find the example usage for org.openqa.selenium.lift.find BaseFinder BaseFinder.

Prototype

BaseFinder

Source Link

Usage

From source file:org.openmrs.Steps.java

License:Mozilla Public License

/**
 * A finder which returns the first element matched - such as if you have multiple elements
 * which match the finder (such as multiple links with the same text on a page etc)
 *///from  ww  w  .j av  a2s.c o m
public static Finder<WebElement, WebDriver> second(final Finder<WebElement, WebDriver> finder) {
    return new BaseFinder<WebElement, WebDriver>() {

        @Override
        public Collection<WebElement> findFrom(WebDriver context) {
            Collection<WebElement> collection = super.findFrom(context);
            if (collection.size() > 1) {
                Iterator<WebElement> iter = collection.iterator();
                iter.next();
                return Collections.singletonList(iter.next());
            } else {
                return collection;
            }
        }

        protected Collection<WebElement> extractFrom(WebDriver context) {
            return finder.findFrom(context);
        }

        protected void describeTargetTo(Description description) {
            description.appendText("second ");
            finder.describeTo(description);
        }
    };
}