Skip to content

Commit cd93e41

Browse files
SjorsOtaylorotwell
andauthored
[6.x] Try clicking all elements before throwing ElementClickInterceptedException (#989)
* attempt to click all elements before failing * remove unused import * Update InteractsWithMouse.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent abcc4bd commit cd93e41

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Concerns/InteractsWithMouse.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Laravel\Dusk\Concerns;
44

5+
use Facebook\WebDriver\Exception\ElementClickInterceptedException;
6+
use Facebook\WebDriver\Exception\NoSuchElementException;
57
use Facebook\WebDriver\Interactions\WebDriverActions;
68
use Facebook\WebDriver\WebDriverBy;
79

@@ -48,11 +50,21 @@ public function click($selector = null)
4850
{
4951
if (is_null($selector)) {
5052
(new WebDriverActions($this->driver))->click()->perform();
51-
} else {
52-
$this->resolver->findOrFail($selector)->click();
53+
54+
return $this;
5355
}
5456

55-
return $this;
57+
foreach ($this->resolver->all($selector) as $element) {
58+
try {
59+
$element->click();
60+
61+
return $this;
62+
} catch (ElementClickInterceptedException $e) {
63+
//
64+
}
65+
}
66+
67+
throw $e ?? new NoSuchElementException("Unable to locate element with selector [{$selector}].");
5668
}
5769

5870
/**

0 commit comments

Comments
 (0)