Skip to content

Instantly share code, notes, and snippets.

@litzinger
Created March 10, 2017 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save litzinger/904e9c4018b7494ade618b33c97ad5f9 to your computer and use it in GitHub Desktop.
Save litzinger/904e9c4018b7494ade618b33c97ad5f9 to your computer and use it in GitHub Desktop.
fillField method that works in Safari
<?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