Skip to content

Commit d8adafd

Browse files
hchonovaik099
authored andcommitted
Prevent firing the "change" event twice (#286)
Prevent firing the "change" event twice in Google Chrome
1 parent 93474c6 commit d8adafd

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/Selenium2Driver.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,20 @@ public function setValue($xpath, $value)
683683
}
684684

685685
$element->postValue(array('value' => array($value)));
686-
$this->trigger($xpath, 'change');
686+
// Remove the focus from the element if the field still has focus in
687+
// order to trigger the change event. By doing this instead of simply
688+
// triggering the change event for the given xpath we ensure that the
689+
// change event will not be triggered twice for the same element if it
690+
// has lost focus in the meanwhile. If the element has lost focus
691+
// already then there is nothing to do as this will already have caused
692+
// the triggering of the change event for that element.
693+
$script = <<<JS
694+
var node = {{ELEMENT}};
695+
if (document.activeElement === node) {
696+
document.activeElement.blur();
697+
}
698+
JS;
699+
$this->executeJsOnElement($element, $script);
687700
}
688701

689702
/**

0 commit comments

Comments
 (0)