minkphp / MinkSelenium2Driver

Selenium2 (webdriver) driver for Mink framework
MIT License
507 stars 163 forks source link

Fix StaleElementException in setValue when input has gone away #336

Closed Chekote closed 3 years ago

Chekote commented 3 years ago

Problem

Some websites using a SPA approach have implemented behavior where when a correct value is entered into an input, it is immediately recognized and the SPA updates instantly, causing the input to be detached from the DOM.

e.g. a 2FA input field that immediately recognizes the correct value as it is typed, and causes the SPA to update the page instantly if it is correct.

When this happens, the input is set correctly via the $element->postValue() call from setValue(), but when it then proceeds to call $this->executeJsOnElement(), a StaleElementException is thrown because the input is no longer attached to the DOM.

Fix

Catch and swallow the exception.

Rationale

It is not possible to execute JS on an element that is detached from the DOM, so it is impossible to attempt to unfocus it at this point (at least by executing JS on it).

The goal is to unfocus the element, which if it is detached from the DOM, it is clearly unfocused at this point.

Chekote commented 3 years ago

Seems like your Travis CI is broken? It didn't run on the PR.

Chekote commented 3 years ago

@aik099 sorry to bug you, but I wanted to make sure you saw this PR since your CI seems to be broken.

aik099 commented 3 years ago

Nice bug report by the way. Very detailed. Thank you @Chekote .

aik099 commented 3 years ago

Merging, thanks @Chekote .