Created
March 10, 2017 16:15
-
-
Save litzinger/904e9c4018b7494ade618b33c97ad5f9 to your computer and use it in GitHub Desktop.
fillField method that works in Safari
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://codete.com/blog/automating-acceptance-testing/ | |
/** | |
* Fills a text field or textarea with the given string. | |
* | |
* @param string $field field | |
* @param string $value value | |
* | |
* @return void | |
*/ | |
public function fillField($field, $value) | |
{ | |
if ($this->isWebDriver() && $this->getAgent() == self::AGENT_SAFARI) { | |
$js = <<< JS | |
var event = document.createEvent('TextEvent'); | |
event.initTextEvent('textInput', true, true, null, '{$value}'); | |
\$('{$field}')[0].focus(); | |
\$('{$field}')[0].dispatchEvent(event); | |
JS; | |
$this->scrollIntoView($field); | |
$this->executeJS($js); | |
} else { | |
$this->runner->fillField($field, $value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment