Skip to content

Commit fddff98

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: Add doc about how to get a link by its id or class attribute in DOM crawler page
2 parents 1744c24 + 0bf7cb3 commit fddff98

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

components/dom_crawler.rst

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,26 @@ This behavior is best illustrated with examples::
424424
Links
425425
~~~~~
426426

427-
To find a link by name (or a clickable image by its ``alt`` attribute), use
428-
the ``selectLink()`` method on an existing crawler. This returns a ``Crawler``
429-
instance with just the selected link(s). Calling ``link()`` gives you a special
430-
:class:`Symfony\\Component\\DomCrawler\\Link` object::
431-
432-
$linksCrawler = $crawler->selectLink('Go elsewhere...');
433-
$link = $linksCrawler->link();
434-
435-
// or do this all at once
436-
$link = $crawler->selectLink('Go elsewhere...')->link();
427+
Use the ``filter()`` method to find links by their ``id`` or ``class``
428+
attributes and use the ``selectLink()`` method to find links by their content
429+
(it also finds clickable images with that content in its ``alt`` attribute).
430+
431+
Both methods return a ``Crawler`` instance with just the selected link. Use the
432+
``link()`` method to get the :class:`Symfony\\Component\\DomCrawler\\Link` object
433+
that represents the link::
434+
435+
// first, select the link by id, class or content...
436+
$linkCrawler = $crawler->filter('#sign-up');
437+
$linkCrawler = $crawler->filter('.user-profile');
438+
$linkCrawler = $crawler->selectLink('Log in');
439+
440+
// ...then, get the Link object:
441+
$link = $linkCrawler->link();
442+
443+
// or do all this at once:
444+
$link = $crawler->filter('#sign-up')->link();
445+
$link = $crawler->filter('.user-profile')->link();
446+
$link = $crawler->selectLink('Log in')->link();
437447

438448
The :class:`Symfony\\Component\\DomCrawler\\Link` object has several useful
439449
methods to get more information about the selected link itself::

0 commit comments

Comments
 (0)