Check if element present and get first one.

@param element
is {link org.openqa.selenium.By} find in page.
@return first {link org.openqa.selenium.WebElement} finded present element.
486566
public static WebElement isElementPresentAndGetFirstOne(By element) {

        final WebDriver webDriver = Context.getDriver();

        webDriver.manage().timeouts().implicitlyWait(DriverFactory.IMPLICIT_WAIT * 2, TimeUnit.MICROSECONDS);

        final List<WebElement> foundElements = webDriver.findElements(element);
        final boolean exists = !foundElements.isEmpty();

        webDriver.manage().timeouts().implicitlyWait(DriverFactory.IMPLICIT_WAIT, TimeUnit.MICROSECONDS);

        if (exists) {
            return foundElements.get(0);
        } else {
            return null;
        }

    }
1171630
def contains_element(self, element):
        
        return (element in self.element_finder) and \
            (self.element_finder[element][1] != self.INVALID)
1063554
private XmlElementFinder getElementFinder(final Element element) {
		if (elementFinder == null) {
			elementFinder = new XmlElementFinder(element.getDocument());
		}
		return elementFinder;
	}
785937
public T removeFirst() {
		if (isEmpty()) {
			return null;
		}
		T firstElement = elements[firstIndex];
		elements[firstIndex] = null;
		firstIndex = incrementIndex(firstIndex, 0);
		return firstElement;
	}
1165331
@Override
  public WebElement findElement() {
    if (cachedElement != null && shouldCache()) {
      return cachedElement;
    }

    WebElement element = searchContext.findElement(by);
    if (shouldCache()) {
      cachedElement = element;
    }

    return element;
  }
1360903
protected WebElement findElement(String by, String using, OperaWebElement el) {
    checkNotNull(using, "Cannot find elements when the selector is null");
    assertConnected();

    using = OperaStrings.escapeJsString(using);
    boolean isAvailable;
    Integer id;
    String script;

    if (el == null) {
      // Search the document
      script =
          "return " + OperaAtom.FIND_ELEMENT + "({\"" + by + "\": \"" + using + "\"})";
    } else {
      // Search within an element
      script =
          "return " + OperaAtom.FIND_ELEMENT + "({\"" + by + "\": \"" + using
          + "\"}, locator)";
    }

    if (el == null) {
      id = debugger.getObject(script);
    } else {
      id = debugger.executeScriptOnObject(script, el.getObjectId());
    }

    isAvailable = (id != null);

    if (isAvailable) {
      String error =
          debugger.callFunctionOnObject("return (locator instanceof Error) ? locator.message : ''",
                                        id);
      if (!error.isEmpty()) {
        throw new InvalidSelectorException(error);
      }

      Boolean isStale =
          Boolean.valueOf(debugger.callFunctionOnObject("locator.parentNode == undefined", id));

      if (isStale) {
        throw new StaleElementReferenceException("This element is no longer part of DOM");
      }

      return new OperaWebElement(this, id);
    } else {
      throw new NoSuchElementException("Cannot find element(s) with " + by);
    }
  }
55378
public static WebElement findElementOrFail(WebDriver webDriver, By element) {
		try {
			return webDriver.findElement(element);
		} catch (NoSuchElementException e) {
			fail(String.format("Element %s should exist but it does not.", element.toString()), e);
		}
		/**
		 * Never reached since {@link de.codecentric.zucchini.bdd.util.Assert#fail(String)} fail()} throws
		 * {@link java.lang.AssertionError}.
		 */
		return null;
	}
1353509
public Node<T> get(T element) {
		for (Node<T> node : nodes)
			if (node.element.equals(element))
				return node;
		return null;
	}
1299014
public static HTMLElement element(com.google.gwt.dom.client.Element element) {
        return Js.cast(element);
    }
280576
public Integer getNumberFor(WebElement element) {
        Integer number = null;
        if ("li".equalsIgnoreCase(element.getTagName())
                && element.isDisplayed()) {
            int num;
            String ownVal = element.getAttribute("value");
            if (ownVal != null && !"0".equals(ownVal)) {
                num = toInt(ownVal, 0);
            } else {
                String start = element.findElement(By.xpath("ancestor::ol")).getAttribute("start");
                num = toInt(start, 1);

                List<WebElement> allItems = element.findElements(By.xpath("ancestor::ol/li"));
                int index = allItems.indexOf(element);
                for (int i = 0; i < index; i++) {
                    WebElement item = allItems.get(i);
                    if (item.isDisplayed()) {
                        num++;
                        String val = item.getAttribute("value");
                        int valNum = toInt(val, num);
                        if (valNum != 0) {
                            num = valNum + 1;
                        }
                    }
                }
            }
            number = num;
        }
        return number;
    }
739634
public T findElement(SearchContext context, By by) {
        return FirstElementBy.getWebElement(by, context);
    }
1321805
public TreeElement getNode(String element) {
		TreeElement node = null;
		Enumeration<TreeNode> elements = root.children();
		while (elements.hasMoreElements()) {
			TreeElement currentNode = (TreeElement) elements.nextElement();
			if (currentNode instanceof QueryGroupTreeElement) {
				QueryGroupTreeElement groupTElement = (QueryGroupTreeElement) currentNode;
				if (groupTElement.getID().equals(element)) {
					node = groupTElement;
					break;
				}
			}
			if (currentNode instanceof QueryTreeElement) {
				QueryTreeElement queryTreeElement = (QueryTreeElement) currentNode;
				if (queryTreeElement.getID().equals(element)) {
					node = queryTreeElement;
					break;
				}
			}
		}
		return node;
	}
744514
public static Element getElement(Element element, String tagName) {
		final NodeList nodeList = element.getElementsByTagName(tagName);
		if (nodeList == null || nodeList.getLength() < 1) {
			return null;
		}
		int length = nodeList.getLength();
		for (int i = 0; i < length; i++) {
			Element childEle = (Element) nodeList.item(i);
			if (childEle == null || childEle.getParentNode() == element) {
				return childEle;
			}
		}
		return null;
	}
1222892
static final String xpath(Element element) {
        StringBuilder sb = new StringBuilder();

        Node iterator = element;
        while (iterator.getNodeType() == Node.ELEMENT_NODE) {
            sb.insert(0, "]");
            sb.insert(0, siblingIndex((Element) iterator) + 1);
            sb.insert(0, "[");
            sb.insert(0, ((Element) iterator).getTagName());
            sb.insert(0, "/");

            iterator = iterator.getParentNode();
        }

        return sb.toString();
    }
1301040
public ElementView getElementView(@Nonnull Element element) {
        Optional<ElementView> elementView = this.elementViews.stream().filter(ev -> ev.getId().equals(element.getId())).findFirst();
        return elementView.orElse(null);
    }
181035
public static boolean contains(Iterator<?> iterator, Object element) {
        if (iterator != null) {
            while (iterator.hasNext()) {
                Object candidate = iterator.next();
                if (ObjectUtils.nullSafeEquals(candidate, element)) {
                    return true;
                }
            }
        }
        return false;
    }
202729
public String getElement(int i) throws ArrayIndexOutOfBoundsException
  {

    if (null == m_elements)
      throw new ArrayIndexOutOfBoundsException();

    return (String) m_elements.elementAt(i);
  }