Skip to content

Commit d735674

Browse files
committed
[java] Implementing getDomAttribute operation
1 parent 6519fea commit d735674

File tree

6 files changed

+417
-25
lines changed

6 files changed

+417
-25
lines changed

java/client/src/org/openqa/selenium/remote/DriverCommand.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,13 @@ static CommandPayload GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW(String id) {
184184
static CommandPayload GET_ELEMENT_SIZE(String id) {
185185
return new CommandPayload(GET_ELEMENT_SIZE, ImmutableMap.of("id", id));
186186
}
187-
String GET_ELEMENT_PROPERTY = "getElementProperty";
188-
static CommandPayload GET_ELEMENT_PROPERTY(String id, String name) {
189-
return new CommandPayload(GET_ELEMENT_PROPERTY, ImmutableMap.of("id", id, "name", name));
187+
String GET_ELEMENT_DOM_PROPERTY = "getElementDomProperty";
188+
static CommandPayload GET_ELEMENT_DOM_PROPERTY(String id, String name) {
189+
return new CommandPayload(GET_ELEMENT_DOM_PROPERTY, ImmutableMap.of("id", id, "name", name));
190+
}
191+
String GET_ELEMENT_DOM_ATTRIBUTE = "getElementDomAttribute";
192+
static CommandPayload GET_ELEMENT_DOM_ATTRIBUTE(String id, String name) {
193+
return new CommandPayload(GET_ELEMENT_DOM_ATTRIBUTE, ImmutableMap.of("id", id, "name", name));
190194
}
191195
String GET_ELEMENT_ATTRIBUTE = "getElementAttribute";
192196
static CommandPayload GET_ELEMENT_ATTRIBUTE(String id, String name) {
@@ -218,7 +222,7 @@ static CommandPayload SET_ALERT_VALUE(String keysToSend) {
218222
@Deprecated
219223
static CommandPayload SET_IMPLICIT_WAIT_TIMEOUT(long time, TimeUnit unit) {
220224
return new CommandPayload(
221-
SET_TIMEOUT, ImmutableMap.of("implicit", TimeUnit.MILLISECONDS.convert(time, unit)));
225+
SET_TIMEOUT, ImmutableMap.of("implicit", TimeUnit.MILLISECONDS.convert(time, unit)));
222226
}
223227

224228
static CommandPayload SET_IMPLICIT_WAIT_TIMEOUT(Duration duration) {
@@ -228,7 +232,7 @@ static CommandPayload SET_IMPLICIT_WAIT_TIMEOUT(Duration duration) {
228232
@Deprecated
229233
static CommandPayload SET_SCRIPT_TIMEOUT(long time, TimeUnit unit) {
230234
return new CommandPayload(
231-
SET_TIMEOUT, ImmutableMap.of("script", TimeUnit.MILLISECONDS.convert(time, unit)));
235+
SET_TIMEOUT, ImmutableMap.of("script", TimeUnit.MILLISECONDS.convert(time, unit)));
232236
}
233237

234238
static CommandPayload SET_SCRIPT_TIMEOUT(Duration duration) {
@@ -238,7 +242,7 @@ static CommandPayload SET_SCRIPT_TIMEOUT(Duration duration) {
238242
@Deprecated
239243
static CommandPayload SET_PAGE_LOAD_TIMEOUT(long time, TimeUnit unit) {
240244
return new CommandPayload(
241-
SET_TIMEOUT, ImmutableMap.of("pageLoad", TimeUnit.MILLISECONDS.convert(time, unit)));
245+
SET_TIMEOUT, ImmutableMap.of("pageLoad", TimeUnit.MILLISECONDS.convert(time, unit)));
242246
}
243247

244248
static CommandPayload SET_PAGE_LOAD_TIMEOUT(Duration duration) {
@@ -315,19 +319,19 @@ static CommandPayload IME_ACTIVATE_ENGINE(String engine) {
315319
String SET_CURRENT_WINDOW_POSITION = "setWindowPosition";
316320
static CommandPayload SET_CURRENT_WINDOW_POSITION(Point targetPosition) {
317321
return new CommandPayload(
318-
SET_CURRENT_WINDOW_POSITION, ImmutableMap.of("x", targetPosition.x, "y", targetPosition.y));
322+
SET_CURRENT_WINDOW_POSITION, ImmutableMap.of("x", targetPosition.x, "y", targetPosition.y));
319323
}
320324
String GET_CURRENT_WINDOW_POSITION = "getWindowPosition";
321325
static CommandPayload GET_CURRENT_WINDOW_POSITION() {
322326
return new CommandPayload(
323-
GET_CURRENT_WINDOW_POSITION, ImmutableMap.of("windowHandle", "current"));
327+
GET_CURRENT_WINDOW_POSITION, ImmutableMap.of("windowHandle", "current"));
324328
}
325329

326330
// W3C compatible Window API
327331
String SET_CURRENT_WINDOW_SIZE = "setCurrentWindowSize";
328332
static CommandPayload SET_CURRENT_WINDOW_SIZE(Dimension targetSize) {
329333
return new CommandPayload(
330-
SET_CURRENT_WINDOW_SIZE, ImmutableMap.of("width", targetSize.width, "height", targetSize.height));
334+
SET_CURRENT_WINDOW_SIZE, ImmutableMap.of("width", targetSize.width, "height", targetSize.height));
331335
}
332336
String GET_CURRENT_WINDOW_SIZE = "getCurrentWindowSize";
333337
String MAXIMIZE_CURRENT_WINDOW = "maximizeCurrentWindow";

java/client/src/org/openqa/selenium/remote/RemoteWebElement.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ public void sendKeys(CharSequence... keysToSend) {
9898
String allKeysToSend = String.join("", keysToSend);
9999

100100
List<File> files = Arrays.stream(allKeysToSend.split("\n"))
101-
.map(fileDetector::getLocalFile)
102-
.collect(Collectors.toList());
101+
.map(fileDetector::getLocalFile)
102+
.collect(Collectors.toList());
103103
if (!files.isEmpty() && !files.contains(null)) {
104104
allKeysToSend = files.stream()
105-
.map(this::upload)
106-
.collect(Collectors.joining("\n"));
105+
.map(this::upload)
106+
.collect(Collectors.joining("\n"));
107107
}
108108

109109
execute(DriverCommand.SEND_KEYS_TO_ELEMENT(id, new CharSequence[]{allKeysToSend}));
@@ -137,7 +137,14 @@ public String getTagName() {
137137
@Override
138138
public String getDomProperty(String name) {
139139
return stringValueOf(
140-
execute(DriverCommand.GET_ELEMENT_PROPERTY(id, name))
140+
execute(DriverCommand.GET_ELEMENT_DOM_PROPERTY(id, name))
141+
.getValue());
142+
}
143+
144+
@Override
145+
public String getDomAttribute(String name) {
146+
return stringValueOf(
147+
execute(DriverCommand.GET_ELEMENT_DOM_ATTRIBUTE(id, name))
141148
.getValue());
142149
}
143150

@@ -355,9 +362,7 @@ public Point inViewPort() {
355362

356363
@SuppressWarnings("unchecked")
357364
Map<String, Number> mapped = (Map<String, Number>) response.getValue();
358-
return new Point(mapped.get("x")
359-
.intValue(), mapped.get("y")
360-
.intValue());
365+
return new Point(mapped.get("x").intValue(), mapped.get("y").intValue());
361366
}
362367

363368
@Override
@@ -384,10 +389,10 @@ public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException
384389
String base64EncodedPng = new String((byte[]) result, UTF_8);
385390
return outputType.convertFromBase64Png(base64EncodedPng);
386391
} else {
387-
throw new RuntimeException(String.format("Unexpected result for %s command: %s",
392+
throw new RuntimeException(String.format(
393+
"Unexpected result for %s command: %s",
388394
DriverCommand.ELEMENT_SCREENSHOT,
389-
result == null ? "null" : result.getClass()
390-
.getName() + " instance"));
395+
result == null ? "null" : result.getClass().getName() + " instance"));
391396
}
392397
}
393398

java/client/src/org/openqa/selenium/remote/codec/AbstractHttpCommandCodec.java

-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_CONTEXT_HANDLE;
5151
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_URL;
5252
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_LOCATION;
53-
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_PROPERTY;
5453
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_RECT;
5554
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_SIZE;
5655
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_TAG_NAME;
@@ -171,7 +170,6 @@ public AbstractHttpCommandCodec() {
171170
defineCommand(FIND_ELEMENTS, post(sessionId + "/elements"));
172171

173172
String elementId = sessionId + "/element/:id";
174-
defineCommand(GET_ELEMENT_PROPERTY, get(elementId + "/property/:name"));
175173
defineCommand(CLICK_ELEMENT, post(elementId + "/click"));
176174
defineCommand(CLEAR_ELEMENT, post(elementId + "/clear"));
177175
defineCommand(GET_ELEMENT_VALUE_OF_CSS_PROPERTY, get(elementId + "/css/:propertyName"));

java/client/src/org/openqa/selenium/remote/codec/w3c/W3CHttpCommandCodec.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_POSITION;
3939
import static org.openqa.selenium.remote.DriverCommand.GET_CURRENT_WINDOW_SIZE;
4040
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_ATTRIBUTE;
41+
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_DOM_ATTRIBUTE;
4142
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_LOCATION;
4243
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW;
43-
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_PROPERTY;
44+
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_DOM_PROPERTY;
4445
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_RECT;
4546
import static org.openqa.selenium.remote.DriverCommand.GET_ELEMENT_SIZE;
4647
import static org.openqa.selenium.remote.DriverCommand.GET_LOCAL_STORAGE_ITEM;
@@ -159,7 +160,8 @@ public W3CHttpCommandCodec() {
159160
defineCommand(CLEAR_ACTIONS_STATE, delete(sessionId + "/actions"));
160161

161162
String elementId = sessionId + "/element/:id";
162-
defineCommand(GET_ELEMENT_PROPERTY, get(elementId + "/property/:name"));
163+
defineCommand(GET_ELEMENT_DOM_PROPERTY, get(elementId + "/property/:name"));
164+
defineCommand(GET_ELEMENT_DOM_ATTRIBUTE, get(elementId + "/attribute/:name"));
163165

164166
// Emulate the old Actions API since everyone still likes to call these things.
165167
alias(CLICK, ACTIONS);

0 commit comments

Comments
 (0)