Skip to content

Improve DomCrawler's "The current node list is empty" #36816

@pevdh

Description

@pevdh

I've been using the DomCrawler to create functional tests for a little while now. While it's a very robust and easy to use component, a major pain point is whenever a test fails with an InvalidArgumentException: "The current node list is empty".

I use these kind of constructs frequently:

$crawler = $browser->request('GET', '/');

$crawler = $browser->submit($crawler->filter('#some-form')->form(), [
    /* form values */
]);

or:

$messageContent = $crawler->filter('ul li.message-content')->text();

Methods such as form() and text() will fail if the crawler cannot find the selector.

While PHPUnit of course provides the exact line number where the error occurred, I think it would improve DX a lot if the error message contained more information such as the CSS/XPath selectors that were used.

For example:

InvalidArgumentException : No nodes matched the selector '#some-form'

I would have no issue making a PR for this issue, but since it would be my first time contributing I thought I'd seek more input first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)DomCrawlerStalled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions