From 214db602a5da7bb34e47189cad9c1398c5fbb43f Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 10 Mar 2020 18:24:28 +0100 Subject: [PATCH] Fix the value for a select without option --- src/BrowserKitDriver.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/BrowserKitDriver.php b/src/BrowserKitDriver.php index b03e6d3..0f96778 100644 --- a/src/BrowserKitDriver.php +++ b/src/BrowserKitDriver.php @@ -425,7 +425,15 @@ public function getValue($xpath) return $this->getAttribute($xpath, 'value'); } - return $field->getValue(); + $value = $field->getValue(); + + if ('select' === $node->tagName && null === $value) { + // symfony/dom-crawler returns null as value for a non-multiple select without + // options but we want an empty string to match browsers. + $value = ''; + } + + return $value; } /**