Problems with Symfony Panther and lists

Viewed 17

Trying to use symfony panther, I had a problem with lists (ul li html tags) when trying to get the text of the 'parent' tag, for example

<div id='index'>
  <ul>
    <li> 
      <a href='somewhere1'> 1 </a>
      <ul>
        <li><a href='somewhere11'> 1.1 </a></li>
        <li><a href='somewhere12'> 1.2 </a></li>
      </ul>
    </li>  
  </ul>
</div>
  $crawler = $client->waitFor('#index > ul');
  $crawler->filter('#index > ul > li')->each(
    static function (NewCrawler $crawler): void {
      var_dump($crawler->text());
    }
  );

print: string() "1 1.1 1.2 "

How can i print only "1" and then iterate over the 'childrens' so that i print separately: "1.1" and "1.2" (or an array containing each element as a tree)

regards

0 Answers
Related