Skip to content

Commit

Permalink
[6.x] Try clicking all elements before throwing `ElementClickIntercep…
Browse files Browse the repository at this point in the history
…tedException` (#989)

* attempt to click all elements before failing

* remove unused import

* Update InteractsWithMouse.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
SjorsO and taylorotwell authored Jul 25, 2022
1 parent abcc4bd commit cd93e41
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Concerns/InteractsWithMouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Laravel\Dusk\Concerns;

use Facebook\WebDriver\Exception\ElementClickInterceptedException;
use Facebook\WebDriver\Exception\NoSuchElementException;
use Facebook\WebDriver\Interactions\WebDriverActions;
use Facebook\WebDriver\WebDriverBy;

Expand Down Expand Up @@ -48,11 +50,21 @@ public function click($selector = null)
{
if (is_null($selector)) {
(new WebDriverActions($this->driver))->click()->perform();
} else {
$this->resolver->findOrFail($selector)->click();

return $this;
}

return $this;
foreach ($this->resolver->all($selector) as $element) {
try {
$element->click();

return $this;
} catch (ElementClickInterceptedException $e) {
//
}
}

throw $e ?? new NoSuchElementException("Unable to locate element with selector [{$selector}].");
}

/**
Expand Down

0 comments on commit cd93e41

Please sign in to comment.