Skip to content

Commit

Permalink
Prevent firing the "change" event twice (#286)
Browse files Browse the repository at this point in the history
Prevent firing the "change" event twice in Google Chrome
  • Loading branch information
hchonov authored and aik099 committed Jun 25, 2018
1 parent 93474c6 commit d8adafd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,20 @@ public function setValue($xpath, $value)
}

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

/**
Expand Down

0 comments on commit d8adafd

Please sign in to comment.