public static <T extends WebElement> T findElement(By by, SearchContext context) {
        WebElement element = null;
        List<WebElement> elements = context.findElements(by);
        if (elements.size() == 1) {
            element = elements.get(0);
        } else if (elements.size() > 1) {
            element = BEST_FUNCTION.apply(context, elements);
        }
        return (T) element;
    }
public static < T extends WebElement > T findElement ( By by , SearchContext context ) { WebElement element = null ; List < WebElement > elements = context . findElements ( by ) ; if ( elements . size ( ) == 1 ) { element = elements . get ( 0 ) ; } else if ( elements . size ( ) > 1 ) { element = BEST_FUNCTION . apply ( context , elements ) ; } return ( T ) element ; }
Returns 'best' result from by.
If there is no result: returns null,
if there is just one that is best,
otherwise the 'bestFunction' is applied to all results to determine best.
@param by by to use to find elements.
@param context context to search in.
@param <T> type of element expected.
@return 'best' element, will be <code>null</code> if no elements were found.