diff --git a/core/tests/Drupal/Tests/WebAssert.php b/core/tests/Drupal/Tests/WebAssert.php index aa8b642..5c3a346 100644 --- a/core/tests/Drupal/Tests/WebAssert.php +++ b/core/tests/Drupal/Tests/WebAssert.php @@ -426,22 +426,19 @@ public function fieldDisabled($field, TraversableElement $container = NULL) { * {@inheritdoc} */ public function fieldExists($field, TraversableElement $container = NULL, $include_hidden_fields = FALSE) { - if (!$include_hidden_fields) { - return parent::fieldExists($field, $container); - } - try { return parent::fieldExists($field, $container); } - catch (ElementNotFoundException $element_not_found_exception) { - // Try once again with the 'named_partial_including_hidden' selector to - // grab the hidden fields. - $container = $container ?: $this->session->getPage(); - $items = $container->findAll('named_partial_including_hidden', ['field', $field]); - if (!$items) { - throw $element_not_found_exception; + catch (ElementNotFoundException $exception) { + if ($include_hidden_fields) { + // Try once again with the 'named_partial_including_hidden' selector to + // get potential hidden fields. + $container = $container ?: $this->session->getPage(); + if ($node = $container->find('named_partial_including_hidden', ['field', $field])) { + return $node; + } } - return current($items); + throw $exception; } }