Skip to content

Commit 394e6ad

Browse files
authored
Fix StaleElementException in setValue when input has gone away (#336)
Fix StaleElementException in setValue when input has gone away
1 parent b219a04 commit 394e6ad

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/Selenium2Driver.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Behat\Mink\Selector\Xpath\Escaper;
1515
use WebDriver\Element;
1616
use WebDriver\Exception\NoSuchElement;
17+
use WebDriver\Exception\StaleElementReference;
1718
use WebDriver\Exception\UnknownCommand;
1819
use WebDriver\Exception\UnknownError;
1920
use WebDriver\Exception;
@@ -707,7 +708,15 @@ public function setValue($xpath, $value)
707708
document.activeElement.blur();
708709
}
709710
JS;
710-
$this->executeJsOnElement($element, $script);
711+
712+
// Cover case, when an element was removed from DOM after its value was
713+
// changed (e.g. by a JavaScript of a SPA) and therefore can't be focused.
714+
try {
715+
$this->executeJsOnElement($element, $script);
716+
} catch (StaleElementReference $e) {
717+
// Do nothing because an element was already removed and therefore
718+
// blurring is not needed.
719+
}
711720
}
712721

713722
/**

0 commit comments

Comments
 (0)