Skip to content

Commit 0bf7cb3

Browse files
committed
Merge branch '3.4' into 4.3
* 3.4: Add doc about how to get a link by its id or class attribute in DOM crawler page
2 parents 9132e7c + 488abc5 commit 0bf7cb3

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
@@ -399,16 +399,26 @@ This behavior is best illustrated with examples::
399399
Links
400400
~~~~~
401401

402-
To find a link by name (or a clickable image by its ``alt`` attribute), use
403-
the ``selectLink()`` method on an existing crawler. This returns a ``Crawler``
404-
instance with just the selected link(s). Calling ``link()`` gives you a special
405-
:class:`Symfony\\Component\\DomCrawler\\Link` object::
406-
407-
$linksCrawler = $crawler->selectLink('Go elsewhere...');
408-
$link = $linksCrawler->link();
409-
410-
// or do this all at once
411-
$link = $crawler->selectLink('Go elsewhere...')->link();
402+
Use the ``filter()`` method to find links by their ``id`` or ``class``
403+
attributes and use the ``selectLink()`` method to find links by their content
404+
(it also finds clickable images with that content in its ``alt`` attribute).
405+
406+
Both methods return a ``Crawler`` instance with just the selected link. Use the
407+
``link()`` method to get the :class:`Symfony\\Component\\DomCrawler\\Link` object
408+
that represents the link::
409+
410+
// first, select the link by id, class or content...
411+
$linkCrawler = $crawler->filter('#sign-up');
412+
$linkCrawler = $crawler->filter('.user-profile');
413+
$linkCrawler = $crawler->selectLink('Log in');
414+
415+
// ...then, get the Link object:
416+
$link = $linkCrawler->link();
417+
418+
// or do all this at once:
419+
$link = $crawler->filter('#sign-up')->link();
420+
$link = $crawler->filter('.user-profile')->link();
421+
$link = $crawler->selectLink('Log in')->link();
412422

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

0 commit comments

Comments
 (0)