@@ -152,32 +152,38 @@ public function quit() {
152152 }
153153
154154 /**
155- * Inject a snippet of JavaScript into the page for execution in the context
156- * of the currently selected frame. The executed script is assumed to be
157- * synchronous and the result of evaluating the script will be returned.
155+ * Prepare arguments for JavaScript injection
158156 *
159- * @param string $script The script to inject.
160- * @param array $arguments The arguments of the script.
161- * @return mixed The return value of the script.
157+ * @param array $arguments
158+ * @return array
162159 */
163- public function executeScript ( $ script , array $ arguments = array ()) {
164- $ script = str_replace ( ' " ' , ' \" ' , $ script );
160+ private function prepareScriptArguments ( array $ arguments)
161+ {
165162 $ args = array ();
166163 foreach ($ arguments as $ arg ) {
167164 if ($ arg instanceof WebDriverElement) {
168165 array_push ($ args , array ('ELEMENT ' => $ arg ->getID ()));
169166 } else {
170- // TODO: Handle the case where arg is a collection
171167 if (is_array ($ arg )) {
172- throw new Exception (
173- "executeScript with collection paramatar is unimplemented "
174- );
168+ $ arg = $ this ->prepareScriptArguments ($ arg );
175169 }
176170 array_push ($ args , $ arg );
177171 }
178172 }
173+ return $ args ;
174+ }
179175
180- $ params = array ('script ' => $ script , 'args ' => $ args );
176+ /**
177+ * Inject a snippet of JavaScript into the page for execution in the context
178+ * of the currently selected frame. The executed script is assumed to be
179+ * synchronous and the result of evaluating the script will be returned.
180+ *
181+ * @param string $script The script to inject.
182+ * @param array $arguments The arguments of the script.
183+ * @return mixed The return value of the script.
184+ */
185+ public function executeScript ($ script , array $ arguments = array ()) {
186+ $ params = array ('script ' => $ script , 'args ' => $ this ->prepareScriptArguments ($ arguments ));
181187 $ response = $ this ->executor ->execute ('executeScript ' , $ params );
182188 return $ response ;
183189 }
0 commit comments