diff --git a/src/ElementResolver.php b/src/ElementResolver.php index 7f4db8651..7b79cdf21 100644 --- a/src/ElementResolver.php +++ b/src/ElementResolver.php @@ -410,7 +410,7 @@ public function format($selector) ); if (Str::startsWith($selector, '@') && $selector === $originalSelector) { - $selector = '['.Dusk::$selectorHtmlAttribute.'="'.explode('@', $selector)[1].'"]'; + $selector = preg_replace('/@(\S+)/', '['.Dusk::$selectorHtmlAttribute.'="$1"]', $selector); } return trim($this->prefix.' '.$selector); diff --git a/tests/ElementResolverTest.php b/tests/ElementResolverTest.php index 0ade5543d..2af830bc4 100644 --- a/tests/ElementResolverTest.php +++ b/tests/ElementResolverTest.php @@ -147,6 +147,7 @@ public function test_format_correctly_formats_selectors() $this->assertSame('prefix #second', $resolver->format('@modal-second')); $this->assertSame('prefix #first-third', $resolver->format('@modal-third')); $this->assertSame('prefix [dusk="missing-element"]', $resolver->format('@missing-element')); + $this->assertSame('prefix [dusk="missing-element"] > div', $resolver->format('@missing-element > div')); } public function test_find_by_id_with_colon()