diff --git a/components/dom_crawler.rst b/components/dom_crawler.rst index e23261c996a..46e75662eda 100644 --- a/components/dom_crawler.rst +++ b/components/dom_crawler.rst @@ -201,8 +201,16 @@ Access the node name (HTML tag name) of the first node of the current selection Access the value of the first node of the current selection:: + // if the node does not exist, calling to text() will result in an exception $message = $crawler->filterXPath('//body/p')->text(); + // avoid the exception passing an argument that text() returns when node does not exist + $message = $crawler->filterXPath('//body/p')->text('Default text content'); + +.. versionadded:: 4.3 + + The default argument of ``text()`` was introduced in Symfony 4.3. + Access the attribute value of the first node of the current selection:: $class = $crawler->filterXPath('//body/p')->attr('class'); @@ -298,8 +306,16 @@ and :phpclass:`DOMNode` objects:: Or you can get the HTML of the first node using :method:`Symfony\\Component\\DomCrawler\\Crawler::html`:: + // if the node does not exist, calling to html() will result in an exception $html = $crawler->html(); + // avoid the exception passing an argument that html() returns when node does not exist + $html = $crawler->html('Default HTML content'); + + .. versionadded:: 4.3 + + The default argument of ``html()`` was introduced in Symfony 4.3. + Expression Evaluation ~~~~~~~~~~~~~~~~~~~~~
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: