Search code examples
phpdomsymfonycss-selectorssymfony-components

Certain selector syntax not working in Symfony2's CssSelector component (within DomCrawler)


I have a question about the dom crawler, or more specifically, the CssSelector Component. When I run

$descendants = $crawler->filter('ul > li');

on a multi dimensional list, I get all direct children. But when I run

$descendants = $crawler->filter('ul li');

I expect to get all descendants, but instead I get nothing. What am I doing wrong?


Solution

  • Wouter J was right, it's not possible. But this is an acceptable workaround:

    $descendants = $crawler->filter('ul')->filter('li');