0

A functional test with $form = $crawler->selectButton('input[type=submit]')->form(); fails with

The current node list is empty

Source code:

<form action="/household/_search" class="navbar-form navbar-left" role="search">
    <div class="form-group">
        <input type="text" name="qtext" method="get" class="form-control" placeholder="Full name or ID">
    </div>
    <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
</form>

The result is the same with:

  • selectButton('.btn')
  • filterXPath('span[@class="glyphicon glyphicon-search"]')
  • filter('navbar-form')
  • filter('.btn')
  • filter('input[type="submit"]')
  • filter('input[type=submit]')

What is the correct selector?

luchaninov
  • 6,792
  • 6
  • 60
  • 75
geoB
  • 4,578
  • 5
  • 37
  • 70

2 Answers2

0

You don't have an input of the type submit, you have a button with the type submit.

$form = $crawler->selectButton('button[type=submit]')->form();
Jerodev
  • 32,252
  • 11
  • 87
  • 108
  • This unfortunately also results in `node list is empty`. That and `button[type="submit"]`. – geoB May 10 '16 at 15:17
0

As you can see on the documentation, to get a form in the crawler, it should match the id or name for buttons.

Assume your button has an id="submit-form" then your form in test should :

$crawler->selectButton('submit-form')->form();

Check here for the doc. Hope it will help

  • This is close enough. The eventual solution required clearing the test cache and modifying the source code to fit the test. The form tag was modified to include `id="household_search"` and the test was modified to `$form = $crawler->filter('#household_search')->form();` – geoB May 10 '16 at 16:20
  • Oh yeah almost there :) – Anthony Matignon May 10 '16 at 16:30