Filters the list of nodes with a CSS selector.

This method only works if you have installed the CssSelector Symfony Component.

@param string $selector A CSS selector

@return self

@throws \RuntimeException if the CssSelector Component is not available
775742
public function filter($selector)
    {
        $converter = $this->createCssSelectorConverter();

        // The CssSelector already prefixes the selector with descendant-or-self::
        return $this->filterRelativeXPath($converter->toXPath($selector));
    }
867730
protected function hasSelectorPlaceholder($selector)
    {
        if (! is_array($selector)) {
            return false;
        }

        foreach ($selector as $parts) {
            foreach ($parts as $part) {
                if (is_array($part)) {
                    return false;
                }
                if (strlen($part) && '%' === $part[0]) {
                    return true;
                }
            }
        }

        return false;
    }
417999
public function selector2xpath($selector)
    {
        $parts = preg_split('/\\s+/', $selector);
        $xpath = "";
        foreach ($parts as $part) {
            if (preg_match('/^([A-Za-z][A-Za-z0-9]*)/', $part, $matches)) {
                $xpath .= "//$matches[1]";
            } else {
                $xpath .= "//*";
            }
            $xfilters = array();
            if (preg_match('/#([^#.\[]+)/', $part, $matches)) {
                $xfilters[] = "@id='$matches[1]'";
            }
            if (preg_match('/\.([^#.\[]+)/', $part, $matches)) {
                $xfilters[] = "contains(@class,'$matches[1]')";
            }
            if ($xfilters) {
                $xpath .= '[' . implode(',', $xfilters) . ']';
            }
        }
        return $xpath;
    }
431024
public function applyRule($selector, $style)
    {
        if($selector) {
            $nodes = $this->_getNodesForCssSelector($selector);
            $style = $this->_styleToArray($style);

            foreach($nodes as $node) {
                $current = $node->hasAttribute("style") ?
                    $this->_styleToArray($node->getAttribute("style")) :
                    array();

                $current = $this->_mergeStyles($current, $style);

                $node->setAttribute("style", $this->_arrayToStyle($current));
            }
        }

        return $this;
    }
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')" );
	}
907282
protected function getSelectedNode(\DOMDocument $dom, string $selector): \DOMNode
    {
        $xPath = new \DOMXPath($dom);

        return $xPath->query((new CssSelectorConverter())->toXPath($selector))->item(0);
    }
364734
public function parent($selector = null) {
        $results = $this->_walkPathUntil('parentNode', null, $selector, self::$MATCH_TYPE_FIRST);

        return $this->result($results);
    }
1279015
private function buildExpressionForSelector(string $selector)
    {

        if ($expression = $this->resultCache->fetch($selector)) {
            return $expression;
        }

        try {
            $expression = $this->cssConverter->toXPath($selector);
        } catch (ExpressionErrorException $expressionErrorException) {

            // Allow for pseudo selectors
            // TODO: Find a way to validate this exception without checking strings
            if ($expressionErrorException->getMessage() !== 'Pseudo-elements are not supported.') {
                return false;
            }

            try {
                $tokens = explode(':', $selector);
                $expression = $this->cssConverter->toXPath((string)reset($tokens));
            } catch (Exception $e) {
                return false;
            }

        } catch (ExceptionInterface $e) {
            return false;
        }


        $this->resultCache->save($selector, $expression);

        return $expression;
    }
522336
public function seeElementCount($selector, $count)
    {
        $this->assertCount($count, $this->crawler->filter($selector));

        return $this;
    }
712794
public function click($selector = null)
    {
        if (is_null($selector)) {
            (new WebDriverActions($this->driver))->click()->perform();
        } else {
            $this->resolver->findOrFail($selector)->click();
        }

        return $this;
    }
1344589
public function remove( $selector, $key = NULL ){
		if( !$this->sheet )
			throw new RuntimeException( 'No CSS sheet loaded' );
		$result	= $this->sheet->remove( $selector, $key );
		$this->save();
		return $result;
	}
1055805
public function dontSeeElementInDOM($selector, $attributes = [])
    {
        $els = $this->match($this->getBaseElement(), $selector);
        $els = $this->filterByAttributes($els, $attributes);
        $this->assertEmpty($els);
    }
724112
public function withSelector(DocumentSelector $selector): DocumentSource
    {
        $source = clone $this;
        $source->setSelector($selector);

        return $source;
    }
212536
public function remove_selector($selector)
    {
        if ((is_string($selector) || is_int($selector)) && isset($this->data[$selector])) {
            unset($this->data[$selector]);
        }

        return $this;
    }
267650
public function siblings($selector = null): NodeList {
        $results = $this->collection()->reduce(function($carry, $node) use ($selector) {
            return $carry->merge(
                $node->precedingAll($selector)->merge(
                    $node->followingAll($selector)
                )
            );
        }, $this->newNodeList());

        return $results;
    }
1273027
public function elementShouldBeHidden($selector)
    {
        $session = $this->getSession();
        $page = $session->getPage();
        $element = $page->find('css', $selector);

        if (!$element) {
            throw new ElementNotFoundException($session, 'Element "'.$selector.'"');
        }

        \PHPUnit_Framework_TestCase::assertFalse($element->isVisible());
    }
398123
public function element(string $selector): ?Element
    {
        $element = $this->resolver->find($selector);
        return self::convertElement($element, $this->driver);
    }