/** * Executes JS on a given element - pass in a js script string and {{ELEMENT}} will * be replaced with a reference to the element * * @example $this->executeJsOnXpath($xpath, 'return {{ELEMENT}}.childNodes.length'); * * @param Element $element the webdriver element * @param string $script the script to execute * @param Boolean $sync whether to run the script synchronously (default is TRUE) * * @return mixed */ private function executeJsOnElement(Element $element, $script, $sync = true) { $script = str_replace('{{ELEMENT}}', 'arguments[0]', $script); $options = array('script' => $script, 'args' => array(array('ELEMENT' => $element->getID()))); if ($sync) { return $this->wdSession->execute($options); } return $this->wdSession->execute_async($options); }