diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index 3123e570..a1a3e2d9 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -682,8 +682,7 @@ public function setValue($xpath, $value) } $element->postValue(array('value' => array($value))); - $script = 'Syn.trigger("change", {}, {{ELEMENT}})'; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'change'); } /** @@ -821,8 +820,7 @@ public function mouseOver($xpath) */ public function focus($xpath) { - $script = 'Syn.trigger("focus", {}, {{ELEMENT}})'; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'focus'); } /** @@ -830,8 +828,7 @@ public function focus($xpath) */ public function blur($xpath) { - $script = 'Syn.trigger("blur", {}, {{ELEMENT}})'; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'blur'); } /** @@ -840,8 +837,7 @@ public function blur($xpath) public function keyPress($xpath, $char, $modifier = null) { $options = self::charToOptions($char, $modifier); - $script = "Syn.trigger('keypress', $options, {{ELEMENT}})"; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'keypress', $options); } /** @@ -850,8 +846,7 @@ public function keyPress($xpath, $char, $modifier = null) public function keyDown($xpath, $char, $modifier = null) { $options = self::charToOptions($char, $modifier); - $script = "Syn.trigger('keydown', $options, {{ELEMENT}})"; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'keydown', $options); } /** @@ -860,8 +855,7 @@ public function keyDown($xpath, $char, $modifier = null) public function keyUp($xpath, $char, $modifier = null) { $options = self::charToOptions($char, $modifier); - $script = "Syn.trigger('keyup', $options, {{ELEMENT}})"; - $this->withSyn()->executeJsOnXpath($xpath, $script); + $this->trigger($xpath, 'keyup', $options); } /** @@ -1115,4 +1109,15 @@ private function ensureInputType(Element $element, $xpath, $type, $action) throw new DriverException(sprintf($message, $action, $xpath, $type)); } } + + /** + * @param $xpath + * @param $event + * @param string $options + */ + private function trigger($xpath, $event, $options = '{}') + { + $script = 'Syn.trigger("' . $event . '", ' . $options . ', {{ELEMENT}})'; + $this->withSyn()->executeJsOnXpath($xpath, $script); + } }