Find an element by the given selector or throw an exception.

@param  string  $selector
@return \Facebook\WebDriver\Remote\RemoteWebElement
550147
public function findOrFail($selector)
    {
        if (! is_null($element = $this->findById($selector))) {
            return $element;
        }

        return $this->driver->findElement(
            WebDriverBy::cssSelector($this->format($selector))
        );
    }
817808
public function findAll($selector, $locator)
	{
		$items = array();

		foreach ( $this->_nodes as $node ) {
			$items = array_merge($items, $node->findAll($selector, $locator));
		}

		return $items;
	}
331637
public function parent($selector=null)
    {
        $result = $this->createChildInstance();

        if (isset($this->document) && $this->length > 0) {
            foreach ($this->nodes as $node) {
                if ($node->parentNode) {
                    $result->addDomNode($node->parentNode);
                }
            }

            if ($selector) {
                $result = $result->filter($selector);
            }
        }

        return $result;
    }
157386
public function absolutizeAHref($selector = null, $context = null)
    {
        /**
         * @var \DOMElement $item
         */
        if ($selector) {
            foreach ($this->_query->xpath($selector, $context) as $item) {
                if ($item->nodeName === 'a') {
                    $item->setAttribute('href', $this->absolutizeUrl($item->getAttribute('href')));
                } else {
                    $this->absolutizeAHref(null, $item);
                }
            }
        } else {
            foreach ($this->_query->xpath("descendant:://a[not(starts-with(@href, 'http'))]", $context) as $item) {
                $item->setAttribute('href', $this->absolutizeUrl($item->getAttribute('href')));
            }
        }

        return $this;
    }
44090
public function findElements($strategy, $selector)
	{
		return $this->elements($this->using($strategy)->value($selector));
	}
937772
public function getLights($selector = 'all')
    {
        $request = new Request('GET', 'lights/' . $selector);
        $response = $this->sendRequest($request);

        return $response->getBody();
    }
1021528
public function find(string $selector, int $nth = null)
    {
        $selector = new Selector($selector, new SelectorParser());
        $nodes    = $selector->find($this);

        if ( ! is_null($nth)) {
            // return nth-element or array
            if (isset($nodes[$nth])) {
                return $nodes[$nth];
            }

            return null;
        }

        return $nodes;
    }
122887
public function setSelector( $selector )
    {
        $this->selector = empty( $selector )
            ? self::SELECTOR_ALL
            : (string) $selector;

        $matches = array();

        if ( empty( $this->rootParagraphId ) &&
             preg_match( '/#paragraph-(\d+)/', $selector, $matches ) )
        {
            $this->setRootParagraphId( $matches[1] );
        }

        return $this;
    }
1098452
public function find($selector) {
    if (!is_string($selector)) throw new \InvalidArgumentException('Kann bis jetzt nur string als find Parameter');

    $cnt = count($this);
    
    if ($cnt != 1) {
      throw new Exception('Kann bis jetzt nur find() auf Query-Objekten mit genau 1 Element. '.$this->selector.' ('.$cnt.')');
    }

    // erstellt ein Objekt mit dem Document als unser Element
    // mit den matched Elements als das Ergebnis des Selectors in diesem Document
    $Query = new self($selector, $this->getElement());
    $Query->setPrevObject($this);
    $Query->setSelector($this->selector.' '.$selector);
    
    return $Query;
  }
364734
public function parent($selector = null) {
        $results = $this->_walkPathUntil('parentNode', null, $selector, self::$MATCH_TYPE_FIRST);

        return $this->result($results);
    }
949652
public function filter($selector)
    {
        $result = $this->createChildInstance();

        if ($this->length > 0) {
            if (\is_callable($selector)) {
                foreach ($this->nodes as $index => $node) {
                    if ($selector($node, $index)) {
                        $result->addDomNode($node);
                    }
                }
            } else {
                $selection = self::create($this->document)->find($selector);

                foreach ($selection as $result_node) {
                    foreach ($this->nodes as $node) {
                        if ($result_node->isSameNode($node)) {
                            $result->addDomNode($node);
                            break 1;
                        }
                    }
                }
            }
        }

        return $result;
    }
374548
public function value($selector, $value = null)
    {
        if (is_null($value)) {
            return $this->resolver->findOrFail($selector)->getAttribute('value');
        }

        $selector = $this->resolver->format($selector);

        $this->driver->executeScript(
            "document.querySelector('{$selector}').value = '{$value}';"
        );

        return $this;
    }
881970
@Override
    public RemoteWebElement getElement() {
        /*
         * Note: Rationale behind throwing ParentNotFoundException here.
         * 
         * Container's being a parent type is searched using a locator. When the locator is invalid it will be better to
         * throw ParentNotFoundException to the user so that it clearly indicates its the container.
         */
        List<WebElement> elements = null;
        try {
            if (getParent() != null) {
                elements = getParent().locateChildElements(getLocator());
            } else {
                // Its a case where there is a stand alone container and no parent
                elements = HtmlElementUtils.locateElements(getLocator());
            }
        } catch (NoSuchElementException n) {
            throw new ParentNotFoundException("Could not find any parent with the locator " + getLocator(), n);
        }
        if (index <= elements.size()) {
            return (RemoteWebElement) elements.get(index);
        }
        throw new NoSuchElementException("Cannot find Element With index :{" + index + "} in Container"
                + this.getClass().getSimpleName());
    }
825352
public function wait_the_element( $selector )
	{
		$page = $this->getSession()->getPage();

		for ( $i = 0; $i < $this->timeout; $i++ ) {
			try {
				if ( $page->find( 'css', $selector ) ) {
					sleep( 1 );
					return true;
				}
			} catch ( \Exception $e ) {
				// do nothing
			}

			sleep( 1 );
		}

		throw new \Exception( "No html element found for the selector ('$selector')" );
	}
1216473
public function has($selector)
    {
        $result = $this->createChildInstance();

        if ($this->length > 0) {
            foreach ($this as $node) {
                if ($node->find($selector)->length > 0) {
                    $result->addDomNode($node->get(0));
                }
            }
        }

        return $result;
    }
987393
private function convertToParagraph(string $selector): self {
        $nodes = $this->document()->find($selector);

        foreach ($nodes as $node) {
            $tagNodes = $node->find('a, blockquote, dl, div, img, ol, p, pre, table, ul');

            if (!$tagNodes->count()) {
                $this->replaceElementsWithPara($node);
            } else {
                $replacements = $this->getReplacementNodes($node);

                $node->contents()->remove();
                $node->append($replacements);
            }
        }

        return $this;
    }
1211445
public function not($selector)
    {
        $result = $this->createChildInstance();

        if ($this->length > 0) {
            if (\is_callable($selector)) {
                foreach ($this->nodes as $index => $node) {
                    if (!$selector($node, $index)) {
                        $result->addDomNode($node);
                    }
                }
            } else {
                $selection = self::create($this->document)->find($selector);

                if ($selection->length > 0) {
                    foreach ($this->nodes as $node) {
                        $matched = false;
                        foreach ($selection as $result_node) {
                            if ($result_node->isSameNode($node)) {
                                $matched = true;
                                break 1;
                            }
                        }
                        if (!$matched) {
                            $result->addDomNode($node);
                        }
                    }
                } else {
                    $result->addNodes($this->nodes);
                }
            }
        }

        return $result;
    }