From 9a5cf90221780819b5e69c65c2cb11f34956f1ca Mon Sep 17 00:00:00 2001 From: Luke Ring Date: Wed, 5 Oct 2016 10:40:20 +1100 Subject: [PATCH] Implement type() method to use Syn.type. Fixed issue with key{press|down|up} not working on non-input elements. --- src/Selenium2Driver.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Selenium2Driver.php b/src/Selenium2Driver.php index eb6a1e55..05dbcd22 100755 --- a/src/Selenium2Driver.php +++ b/src/Selenium2Driver.php @@ -862,6 +862,21 @@ public function keyUp($xpath, $char, $modifier = null) $this->withSyn()->executeJsOnXpath($xpath, $script); } + /** + * Simulates keyboard typing with Syn.type(). + * See: https://github.com/bitovi/syn/blob/master/src/key.js#L133 + * + * @param string $xpath + * @param string $text example: "Firstname\tLast\tmail@example.org\r" + * + */ + public function type($xpath, $text) + { + $text = json_encode($text); + $script = "Syn.type({{ELEMENT}}, $text)"; + $this->withSyn()->executeJsOnXpath($xpath, $script); + } + /** * {@inheritdoc} */