Search code examples
phpsymfonydomcrawler

Node list is empty: button is glyphicon


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?


Solution

  • 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