From cc062a992bb40eba8c07d7d173f539c393610642 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 24 Sep 2021 12:20:24 +0200 Subject: [PATCH] [DomCrawler] Document innerText() method --- components/dom_crawler.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/dom_crawler.rst b/components/dom_crawler.rst index 8df1b8c8f67..170127b839f 100644 --- a/components/dom_crawler.rst +++ b/components/dom_crawler.rst @@ -230,6 +230,16 @@ Access the value of the first node of the current selection:: // pass FALSE as the second argument to return the original text unchanged $crawler->filterXPath('//body/p')->text('Default text content', false); + // innerText() is similar to text() but returns only the text that is + // the direct descendent of the current node, excluding any child nodes + $text = $crawler->filterXPath('//body/p')->innerText(); + // if content is

Foo Bar

+ // innerText() returns 'Foo' and text() returns 'Foo Bar' + +.. versionadded:: 5.4 + + The ``innerText()`` method was introduced in Symfony 5.4. + Access the attribute value of the first node of the current selection:: $class = $crawler->filterXPath('//body/p')->attr('class');