Skip to content

Commit 6b69522

Browse files
cjayswalshs96c
authored andcommitted
Make newRemoteWebElement protected
- Reverted newRemoteWebElement() method visibility from private to protected so other depending frameworks didn't break. - Fixes : qaf-tm/qaf#119 which was introduced because of newRemoteWebElement method visibility changed from protected to private - minor code improvement to reduce representative statements and it will also support any Dialect added in future. Signed-off-by: Simon Stewart <[email protected]>
1 parent d778865 commit 6b69522

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

java/client/src/org/openqa/selenium/remote/internal/JsonToWebElementConverter.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,11 @@ public Object apply(Object result) {
5050

5151
if (result instanceof Map<?, ?>) {
5252
Map<?, ?> resultAsMap = (Map<?, ?>) result;
53-
if (resultAsMap.containsKey(Dialect.OSS.getEncodedElementKey())) {
54-
RemoteWebElement element = newRemoteWebElement();
55-
element.setId(String.valueOf(resultAsMap.get(Dialect.OSS.getEncodedElementKey())));
56-
return element;
57-
} else if (resultAsMap.containsKey(Dialect.W3C.getEncodedElementKey())) {
58-
RemoteWebElement element = newRemoteWebElement();
59-
element.setId(String.valueOf(resultAsMap.get(Dialect.W3C.getEncodedElementKey())));
60-
return element;
53+
String elementKey = getElementKey(resultAsMap);
54+
if (null!=elementKey) {
55+
RemoteWebElement element = newRemoteWebElement();
56+
element.setId(String.valueOf(resultAsMap.get(elementKey)));
57+
return element;
6158
} else {
6259
return Maps.transformValues(resultAsMap, this);
6360
}
@@ -77,7 +74,7 @@ public Object apply(Object result) {
7774
return result;
7875
}
7976

80-
private RemoteWebElement newRemoteWebElement() {
77+
protected RemoteWebElement newRemoteWebElement() {
8178
return setOwner(new RemoteWebElement());
8279
}
8380

@@ -88,4 +85,13 @@ private RemoteWebElement setOwner(RemoteWebElement element) {
8885
}
8986
return element;
9087
}
88+
private static String getElementKey(Map<?, ?> resultAsMap) {
89+
for (Dialect d : Dialect.values()) {
90+
String elementKeyForDialect = d.getEncodedElementKey();
91+
if (resultAsMap.containsKey(elementKeyForDialect)) {
92+
return elementKeyForDialect;
93+
}
94+
}
95+
return null;
96+
}
9197
}

0 commit comments

Comments
 (0)