code: public static WebElement selectBestElement(SearchContext context, List<WebElement> elements) {
          JavascriptExecutor jse = JavascriptHelper.getJavascriptExecutor(context);
          WebElement element = elements.get(0);
          WebElement firstDisplayed = null;
          WebElement firstOnTop = null;
          if (!element.isDisplayed() || !isOnTop(jse, element)) {
              for (int i = 1; i < elements.size(); i++) {
                  WebElement otherElement = elements.get(i);
                  if (otherElement.isDisplayed()) {
                      if (firstDisplayed == null) {
                          firstDisplayed = otherElement;
                      }
                      if (isOnTop(jse, otherElement)) {
                          firstOnTop = otherElement;
                          element = otherElement;
                          break;
                      }
                  }
              }
              if (firstOnTop == null
                      && firstDisplayed != null
                      && !element.isDisplayed()) {
                  // none displayed and on top
                  // first was not displayed, but another was
                  element = firstDisplayed;
              }
          }
          return element;
      }
docs: Best element is selected as follows:
  Take the first displayed element without any elements on top of it,
  if none: take first displayed, or
  if none are displayed: just take the first.
  @param context context used to find the elements.
  @param elements elements found, from which the best must be selected.
  @return 'best' element from elements.