48
48
import org .openqa .selenium .WebDriverException ;
49
49
import org .openqa .selenium .remote .internal .WebElementToJsonConverter ;
50
50
51
- import java .util .HashMap ;
52
51
import java .io .IOException ;
53
52
import java .net .URL ;
53
+ import java .util .HashMap ;
54
54
import java .util .Map ;
55
55
56
56
/**
@@ -140,16 +140,17 @@ public W3CHttpCommandCodec() {
140
140
141
141
String rawFunction = Resources .toString (url , Charsets .UTF_8 );
142
142
String script = String .format (
143
- "function() { return (%s).apply(null, arguments);} " ,
143
+ "return (%s).apply(null, arguments);" ,
144
144
rawFunction );
145
- return toScript (script , parameters .get ("id" ), parameters .get ("name" ));
146
-
145
+ return toScript (script , asElement (parameters .get ("id" )), parameters .get ("name" ));
147
146
} catch (IOException | NullPointerException e ) {
148
147
throw new WebDriverException (e );
149
148
}
150
149
151
150
case GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW :
152
- return toScript ("return arguments[0].getBoundingClientRect()" , parameters );
151
+ return toScript (
152
+ "return arguments[0].getBoundingClientRect()" ,
153
+ asElement (parameters .get ("id" )));
153
154
154
155
case GET_PAGE_SOURCE :
155
156
return toScript (
@@ -176,7 +177,7 @@ public W3CHttpCommandCodec() {
176
177
"var e = form.ownerDocument.createEvent('Event');\n " +
177
178
"e.initEvent('submit', true, true);\n " +
178
179
"if (form.dispatchEvent(e)) { form.submit() }\n " ,
179
- parameters );
180
+ asElement ( parameters . get ( "id" )) );
180
181
181
182
default :
182
183
return parameters ;
@@ -195,6 +196,10 @@ public W3CHttpCommandCodec() {
195
196
"args" , Lists .newArrayList (convertedArgs ));
196
197
}
197
198
199
+ private Map <String , String > asElement (Object id ) {
200
+ return ImmutableMap .of ("element-6066-11e4-a52e-4f735466cecf" , (String ) id );
201
+ }
202
+
198
203
private String cssEscape (String using ) {
199
204
using = using .replaceAll ("(['\" \\ \\ #.:;,!?+<>=~*^$|%&@`{}\\ -\\ /\\ [\\ ]\\ (\\ )])" , "\\ \\ $1" );
200
205
if (using .length () > 0 && Character .isDigit (using .charAt (0 ))) {
0 commit comments