You are here

protected function FeatureContext::fillFieldByJS in Booking and Availability Management Tools for Drupal 7

Same name and namespace in other branches
  1. 8 test/behat/features/bootstrap/FeatureContext.php \FeatureContext::fillFieldByJS()

Fills a field using JS to avoid event firing.

Parameters

string $field:

string$value:

File

test/behat/features/bootstrap/FeatureContext.php, line 177

Class

FeatureContext
Features context.

Code

protected function fillFieldByJS($field, $value) {
  $field = str_replace('\\"', '"', $field);
  $value = str_replace('\\"', '"', $value);
  $xpath = $this
    ->getSession()
    ->getPage()
    ->findField($field)
    ->getXpath();
  $element = $this
    ->getSession()
    ->getDriver()
    ->getWebDriverSession()
    ->element('xpath', $xpath);
  $elementID = $element
    ->getID();
  $subscript = "arguments[0]";
  $script = str_replace('{{ELEMENT}}', $subscript, '{{ELEMENT}}.value = "' . $value . '"');
  return $this
    ->getSession()
    ->getDriver()
    ->getWebDriverSession()
    ->execute(array(
    'script' => $script,
    'args' => array(
      array(
        'ELEMENT' => $elementID,
      ),
    ),
  ));
}