23
23
import static org .openqa .selenium .remote .DriverCommand .EXECUTE_SCRIPT ;
24
24
import static org .openqa .selenium .remote .DriverCommand .GET_ALERT_TEXT ;
25
25
import static org .openqa .selenium .remote .DriverCommand .GET_CURRENT_WINDOW_HANDLE ;
26
+ import static org .openqa .selenium .remote .DriverCommand .GET_CURRENT_WINDOW_POSITION ;
26
27
import static org .openqa .selenium .remote .DriverCommand .GET_CURRENT_WINDOW_SIZE ;
28
+ import static org .openqa .selenium .remote .DriverCommand .GET_PAGE_SOURCE ;
27
29
import static org .openqa .selenium .remote .DriverCommand .GET_WINDOW_HANDLES ;
28
30
import static org .openqa .selenium .remote .DriverCommand .MAXIMIZE_CURRENT_WINDOW ;
29
31
import static org .openqa .selenium .remote .DriverCommand .SET_ALERT_VALUE ;
@@ -49,20 +51,23 @@ public class W3CHttpCommandCodec extends AbstractHttpCommandCodec {
49
51
50
52
public W3CHttpCommandCodec () {
51
53
52
- defineCommand (GET_WINDOW_HANDLES , get ("/session/:sessionId/window/handles" ));
54
+ defineCommand (EXECUTE_SCRIPT , post ("/session/:sessionId/execute/sync" ));
55
+ defineCommand (EXECUTE_ASYNC_SCRIPT , post ("/session/:sessionId/execute/async" ));
56
+
57
+ defineCommand (GET_PAGE_SOURCE , post ("/session/:sessionId/execute/sync" ));
58
+
53
59
defineCommand (MAXIMIZE_CURRENT_WINDOW , post ("/session/:sessionId/window/maximize" ));
60
+ defineCommand (GET_CURRENT_WINDOW_POSITION , get ("/session/:sessionId/execute/sync" ));
54
61
defineCommand (SET_CURRENT_WINDOW_POSITION , post ("/session/:sessionId/execute/sync" ));
55
62
defineCommand (GET_CURRENT_WINDOW_SIZE , get ("/session/:sessionId/window/size" ));
56
63
defineCommand (SET_CURRENT_WINDOW_SIZE , post ("/session/:sessionId/window/size" ));
57
64
defineCommand (GET_CURRENT_WINDOW_HANDLE , get ("/session/:sessionId/window" ));
65
+ defineCommand (GET_WINDOW_HANDLES , get ("/session/:sessionId/window/handles" ));
58
66
59
67
defineCommand (ACCEPT_ALERT , post ("/session/:sessionId/alert/accept" ));
60
68
defineCommand (DISMISS_ALERT , post ("/session/:sessionId/alert/dismiss" ));
61
69
defineCommand (GET_ALERT_TEXT , get ("/session/:sessionId/alert/text" ));
62
70
defineCommand (SET_ALERT_VALUE , post ("/session/:sessionId/alert/text" ));
63
-
64
- defineCommand (EXECUTE_SCRIPT , post ("/session/:sessionId/execute/sync" ));
65
- defineCommand (EXECUTE_ASYNC_SCRIPT , post ("/session/:sessionId/execute/async" ));
66
71
}
67
72
68
73
@ Override
@@ -114,6 +119,15 @@ public W3CHttpCommandCodec() {
114
119
return toReturn ;
115
120
116
121
122
+ case GET_PAGE_SOURCE :
123
+ return toScript (
124
+ "var source = document.documentElement.outerHTML; \n " +
125
+ "if (!source) { source = new XMLSerializer().serializeToString(document); }\n " +
126
+ "return source;" );
127
+
128
+ case DriverCommand .GET_CURRENT_WINDOW_POSITION :
129
+ return toScript ("return {x: window.screenX, y: window.screenY}" );
130
+
117
131
case DriverCommand .SET_CURRENT_WINDOW_POSITION :
118
132
return toScript (
119
133
"window.screenX = arguments[0]; window.screenY = arguments[1]" ,
0 commit comments