Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nathan-lochala's avatar

PHPunit: Form Ancestor Not Found

I have a simple form:

      <!--NEW FORM-->
<form method="POST" action="http://192.168.114.139/family/search_results" accept-charset="UTF-8" id="admin-form"><input
        name="_token" type="hidden" value="7v2IhbTkiMRVyojJ8Vuv0dDdRqySzO18Z6gPWKP2">
    
    <input class="gui-input" id="search_term" placeholder="" name="search_term" type="text">

    <div class="panel-footer text-right">
        <input class="button btn-primary" name="submit" id="search" type="submit" value="Search">
        <button class="button btn-danger" type="reset">Reset</button>
    </div>
</form>

I want to test this form using Laravel's Laracasts\Integrated package. I have the following test method written:

/** @test */
public function it_can_search()
{
    $this->login()
        ->visit('/identification/search_family/')
        ->see('Search Families')
        ->submitForm('Search',['search_term' => 'tests'])
        ->seePageIs('/identification/search_family/');
}

When I run the test, I get the following error:

There was 1 error:

1) ExampleTest::it_can_seach
LogicException: The selected node does not have a form ancestor.

/var/www/html/srs/vendor/symfony/dom-crawler/Form.php:400
/var/www/html/srs/vendor/symfony/dom-crawler/Link.php:55
/var/www/html/srs/vendor/symfony/dom-crawler/Form.php:49
/var/www/html/srs/vendor/symfony/dom-crawler/Crawler.php:770
/var/www/html/srs/vendor/laracasts/integrated/src/Extensions/IntegrationTrait.php:397
/var/www/html/srs/vendor/laracasts/integrated/src/Extensions/IntegrationTrait.php:380
/var/www/html/srs/vendor/laracasts/integrated/src/Extensions/Traits/LaravelTestCase.php:47
/var/www/html/srs/tests/ExampleTest.php:23

FAILURES!
Tests: 2, Assertions: 8, Errors: 1.

I know the error means the Dom-crawler can't find the form associated with the input, but I don't understand why... Thank you!

0 likes
1 reply

Please or to participate in this conversation.