Behat/MinkSelenium2Driver — pull request #45 by arcturial (2013-05-04 14:36:23+00:00)
Title: setValue() triggers 2 'onchange' events

If you have a scenario where you have ajax triggering on a text field 'onchange' event. It can become a problem if the ajax disables the element until it's done. The setValue() method in the Selenium2Driver class calls clear() and then value() and both of them triggers an 'onchange' event in the browser.

I have modified this so that the setValue() does not clear() a text field but instead uses backspaces to clear the previous value, this way...the onchange event happens only once.

Reason For Change:
-----------------------------

If ajax disables a container upon change, it will cause a simply "I fill in" behat command to fail because when it calls clear() upon the field it triggers the change event...thus cause the value() method to fail due to a disabled element.

Problematic Flow:
--------------------------

I fill in "Number" with "12345"
Call to setValue()
---- Driver triggers clear()
-------- Browser triggers onchange on the field
------------ Javascript disables the field waiting for ajax to complete
---- Driver triggers value()
---- Behat fails because the field is still disabled

Solution:
------------

I fill in "Number" with "12345"
Call to setValue()
---- Driver calls attribute('value') to get the current value
---- Driver calculates the amount of backspaces needed to wipe out current value
---- Driver triggers value() with the amount of backspaces prepended to the new value
------- Browser triggers onchange
------------ Javascript disabled the field waiting for ajax