@@ -387,21 +387,17 @@ returns a ``Crawler`` instance.
387387Use the crawler to find DOM elements in the response. These elements can then
388388be used to click on links and submit forms::
389389
390- $link = $crawler->selectLink('Go elsewhere...')->link();
391- $crawler = $client->click($link);
390+ $crawler = $client->clickLink('Go elsewhere...');
392391
393- $form = $crawler->selectButton('validate')->form();
394- $crawler = $client->submit($form, array('name' => 'Fabien'));
392+ $crawler = $client->submitForm('validate', array('name' => 'Fabien'));
395393
396- The ``click () `` and ``submit () `` methods both return a ``Crawler `` object.
394+ The ``clickLink () `` and ``submitForm () `` methods both return a ``Crawler `` object.
397395These methods are the best way to browse your application as it takes care
398396of a lot of things for you, like detecting the HTTP method from a form and
399397giving you a nice API for uploading files.
400398
401- ..tip ::
402-
403- You will learn more about the ``Link `` and ``Form `` objects in the
404- :ref: `Crawler <testing-crawler >` section below.
399+ ..versionadded ::4.2
400+ The ``clickLink() `` and ``submitForm() `` methods were introduced in Symfony 4.2.
405401
406402The ``request() `` method can also be used to simulate form submissions directly
407403or perform more complex requests. Some useful examples::
@@ -667,65 +663,68 @@ The Crawler can extract information from the nodes::
667663Links
668664~~~~~
669665
670- To select links, you can use thetraversing methods above or the convenient
671- `` selectLink() ``shortcut ::
666+ Use the `` clickLink() `` method to click on thefirst link that contains the
667+ given text (or the first clickable image with that `` alt ``attribute) ::
672668
673- $crawler->selectLink('Click here');
669+ $client = static::createClient();
670+ $client->request('GET', '/post/hello-world');
674671
675- This selects all links that contain the given text, or clickable images for
676- which the ``alt `` attribute contains the given text. Like the other filtering
677- methods, this returns another ``Crawler `` object.
672+ $client->clickLink('Click here');
678673
679- Once you've selected a link, you have access to a special ``Link `` object,
680- which has helpful methods specific to links (such as ``getMethod() `` and
681- ``getUri() ``). To click on the link, use the Client's ``click() `` method
682- and pass it a ``Link `` object::
674+ If you need access to the:class: `Symfony\\ Component\\ DomCrawler\\ Link ` object
675+ that provides helpful methods specific to links (such as ``getMethod() `` and
676+ ``getUri() ``), use the ``selectLink() `` method instead:
683677
684- $link = $crawler->selectLink('Click here')->link();
678+ $client = static::createClient();
679+ $crawler = $client->request('GET', '/post/hello-world');
685680
681+ $link = $crawler->selectLink('Click here')->link();
686682 $client->click($link);
687683
688684Forms
689685~~~~~
690686
691- Forms can be selected using their buttons, which can be selected with the
692- ``selectButton() `` method, just like links::
687+ Use the ``submitForm() `` method to submit the form that contains the given button::
693688
694- $buttonCrawlerNode = $crawler->selectButton('submit');
689+ $client = static::createClient();
690+ $client->request('GET', '/post/hello-world');
691+
692+ $crawler = $client->submitForm('Add comment', array(
693+ 'comment_form[content]' => '...',
694+ ));
695+
696+ The first argument of ``submitForm() `` is the text content, ``id ``, ``value `` or
697+ ``name `` of any ``<button> `` or ``<input type="submit"> `` included in the form.
698+ The second optional argument is used to override the default form field values.
695699
696700..note ::
697701
698702 Notice that you select form buttons and not forms as a form can have several
699703 buttons; if you use the traversing API, keep in mind that you must look for a
700704 button.
701705
702- The ``selectButton() `` method can select ``button `` tags and submit ``input ``
703- tags. It uses several parts of the buttons to find them:
706+ If you need access to the:class: `Symfony\\ Component\\ DomCrawler\\ Form ` object
707+ that provides helpful methods specific to forms (such as ``getUri() ``,
708+ ``getValues() `` and ``getFields() ``) use the ``selectButton() `` method instead::
704709
705- * The ``value `` attribute value;
706- * The ``id `` or ``alt `` attribute value for images;
707- * The ``id `` or ``name `` attribute value for ``button `` tags.
710+ $client = static::createClient();
711+ $crawler = $client->request('GET', '/post/hello-world');
708712
709- Once you have a Crawler representing a button, call the ``form() `` method
710- to get a ``Form `` instance for the form wrapping the button node::
713+ $buttonCrawlerNode = $crawler->selectButton('submit');
711714
715+ // select the form that contains this button
712716 $form = $buttonCrawlerNode->form();
713717
714- When calling the ``form() `` method, you can also pass an array of field values
715- that overrides the default ones::
716-
718+ // you can also pass an array of field values that overrides the default ones
717719 $form = $buttonCrawlerNode->form(array(
718720 'my_form[name]' => 'Fabien',
719721 'my_form[subject]' => 'Symfony rocks!',
720722 ));
721723
722- And if you want to simulate a specific HTTP method for the form, pass it as a
723- second argument::
724-
724+ // you can pass a second argument to override the form HTTP method
725725 $form = $buttonCrawlerNode->form(array(), 'DELETE');
726726
727- The Client can submit ``Form `` instances::
728-
727+ // submit the Form object
729728 $client->submit($form);
730729
731730The field values can also be passed as a second argument of the ``submit() ``
@@ -771,10 +770,11 @@ their type::
771770
772771..tip ::
773772
774- The ``submit() ``method defines a third optionalargument to add custom
775- HTTP headers when submitting the form::
773+ The ``submit() ``and `` submitForm() `` methods define optionalarguments to
774+ add custom server parameters and HTTP headers when submitting the form::
776775
777776 $client->submit($form, array(), array('HTTP_ACCEPT_LANGUAGE' => 'es'));
777+ $client->submitForm($button, array(), 'POST', array('HTTP_ACCEPT_LANGUAGE' => 'es'));
778778
779779 ..versionadded ::4.1
780780 The feature to add custom HTTP headers was introduced in Symfony 4.1.