jmc
jmc

Reputation: 312

Selecting a link-button with the DomCrawler

I'm writing functional tests for my Symfony application.

However, i haven't found a way to click on a link button like this one

<a id="update" title ="Edit this folder" name="update" href="{{ path('folder_edit', { 'id': entity.id }) }}">
    <button class="button-strong">
        Edit
    </button>
</a>

I try to click on it this way :

 $link = $crawler->selectLink("Edit")->link();
 $client->click($link);

I've tried many others ways but without any success.But when I'm running the tests he keeps throwing this exception :

InvalidArgumentException : The current node list is empty

I've looked if there is a way to just click on a button but it seems to be impossible if there is no form linked to it.

Thank you very much.

Upvotes: 0

Views: 1526

Answers (1)

Varun Nath
Varun Nath

Reputation: 5632

Firstly, having a <button> inside a <a> is invalid in HTML 5 and may not work as expected.

Coming to the answer, the reason you are getting that error is due to the difference in whitespace. The crawler will not ignore the whitespace and will thus not find a link that has the text EDIT.

HTML

<a id="update" title ="Edit this folder" name="update" href="#">Edit</a>

TEST

$link = $crawler->selectLink('Edit')->link();
$client->click($link);

Upvotes: 1

Related Questions