diff --git a/components/browser_kit.rst b/components/browser_kit.rst index f36b566c2cf..ecaf886f0f3 100644 --- a/components/browser_kit.rst +++ b/components/browser_kit.rst @@ -97,14 +97,25 @@ make AJAX requests:: Clicking Links ~~~~~~~~~~~~~~ -The ``Crawler`` object is capable of simulating link clicks. First, pass the -text content of the link to the ``selectLink()`` method, which returns a -``Link`` object. Then, pass this object to the ``click()`` method, which -performs the needed HTTP GET request to simulate the link click:: +The ``Client`` object is capable of simulating link clicks. Pass the text +content of the link and the client will perform the needed HTTP GET request to +simulate the link click:: use Acme\Client; $client = new Client(); + $client->request('GET', '/product/123'); + + $crawler = $client->clickLink('Go elsewhere...'); + +.. versionadded:: 4.2 + The ``clickLink()`` method was introduced in Symfony 4.2. + +If you need the :class:`Symfony\\Component\\DomCrawler\\Link` object that +provides access to the link properties (e.g. ``$link->getMethod()``, +``$link->getUri()``), use this other method: + + // ... $crawler = $client->request('GET', '/product/123'); $link = $crawler->selectLink('Go elsewhere...')->link(); $client->click($link); @@ -112,27 +123,51 @@ performs the needed HTTP GET request to simulate the link click:: Submitting Forms ~~~~~~~~~~~~~~~~ -The ``Crawler`` object is also capable of selecting forms. First, select any of -the form's buttons with the ``selectButton()`` method. Then, use the ``form()`` -method to select the form which the button belongs to. - -After selecting the form, fill in its data and send it using the ``submit()`` -method (which makes the needed HTTP POST request to submit the form contents):: +The ``Client`` object is also capable of submitting forms. First, select the +form using any of its buttons and then override any of its properties (method, +field values, etc.) before submitting it:: use Acme\Client; - // make a real request to an external site $client = new Client(); $crawler = $client->request('GET', 'https://github.com/login'); + // find the form with the 'Log in' button and submit it + // 'Log in' can be the text content, id, value or name of a