How can I safely check is node empty or not? (Symfony 2 Crawler)

前端 未结 3 714
-上瘾入骨i
-上瘾入骨i 2021-02-05 03:53

When I try to take some nonexistent content from page I catch this error:

The current node list is empty.
500 Internal Server Error - InvalidArgumentException 
<         


        
3条回答
  •  余生分开走
    2021-02-05 04:58

    Have you tried something like this?

    $text = null;
    if (!empty($body = $crawler->filter('.PropertyBody'))) {
        if (!empty($node = $body->eq(2))) {
            $text = $node->text();
        }
    }
    
    $this->assertContains('yourText', $text);
    

提交回复
热议问题