Skip to content

Commit d729f32

Browse files
committed
Actually make the W3C shim for getAttribute work.
Of course, when using JS, it's important to code the element correctly.
1 parent 4f28354 commit d729f32

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

java/client/src/org/openqa/selenium/remote/http/W3CHttpCommandCodec.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
import org.openqa.selenium.WebDriverException;
4949
import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
5050

51-
import java.util.HashMap;
5251
import java.io.IOException;
5352
import java.net.URL;
53+
import java.util.HashMap;
5454
import java.util.Map;
5555

5656
/**
@@ -140,16 +140,17 @@ public W3CHttpCommandCodec() {
140140

141141
String rawFunction = Resources.toString(url, Charsets.UTF_8);
142142
String script = String.format(
143-
"function() { return (%s).apply(null, arguments);}",
143+
"return (%s).apply(null, arguments);",
144144
rawFunction);
145-
return toScript(script, parameters.get("id"), parameters.get("name"));
146-
145+
return toScript(script, asElement(parameters.get("id")), parameters.get("name"));
147146
} catch (IOException | NullPointerException e) {
148147
throw new WebDriverException(e);
149148
}
150149

151150
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")));
153154

154155
case GET_PAGE_SOURCE:
155156
return toScript(
@@ -176,7 +177,7 @@ public W3CHttpCommandCodec() {
176177
"var e = form.ownerDocument.createEvent('Event');\n" +
177178
"e.initEvent('submit', true, true);\n" +
178179
"if (form.dispatchEvent(e)) { form.submit() }\n",
179-
parameters);
180+
asElement(parameters.get("id")));
180181

181182
default:
182183
return parameters;
@@ -195,6 +196,10 @@ public W3CHttpCommandCodec() {
195196
"args", Lists.newArrayList(convertedArgs));
196197
}
197198

199+
private Map<String, String> asElement(Object id) {
200+
return ImmutableMap.of("element-6066-11e4-a52e-4f735466cecf", (String) id);
201+
}
202+
198203
private String cssEscape(String using) {
199204
using = using.replaceAll("(['\"\\\\#.:;,!?+<>=~*^$|%&@`{}\\-\\/\\[\\]\\(\\)])", "\\\\$1");
200205
if (using.length() > 0 && Character.isDigit(using.charAt(0))) {

0 commit comments

Comments
 (0)