Skip to content

Documented the default values of text() and html() #10898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions components/dom_crawler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 <strong>HTML</strong> content');

.. versionadded:: 4.3

The default argument of ``html()`` was introduced in Symfony 4.3.

Expression Evaluation
~~~~~~~~~~~~~~~~~~~~~

Expand Down