forked from tebeka/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselenium.go
314 lines (277 loc) · 8.17 KB
/
selenium.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package selenium
import (
"time"
)
const (
Version = "0.8.2" // Driver version
)
/* Element finding options */
const (
ById = "id"
ByXPATH = "xpath"
ByLinkText = "link text"
ByPartialLinkText = "partial link text"
ByName = "name"
ByTagName = "tag name"
ByClassName = "class name"
ByCSSSelector = "css selector"
)
/* Mouse buttons */
const (
LeftButton = iota
MiddleButton
RightButton
)
/* Keys */
const (
NullKey = string('\ue000')
CancelKey = string('\ue001')
HelpKey = string('\ue002')
BackspaceKey = string('\ue003')
TabKey = string('\ue004')
ClearKey = string('\ue005')
ReturnKey = string('\ue006')
EnterKey = string('\ue007')
ShiftKey = string('\ue008')
ControlKey = string('\ue009')
AltKey = string('\ue00a')
PauseKey = string('\ue00b')
EscapeKey = string('\ue00c')
SpaceKey = string('\ue00d')
PageUpKey = string('\ue00e')
PageDownKey = string('\ue00f')
EndKey = string('\ue010')
HomeKey = string('\ue011')
LeftArrowKey = string('\ue012')
UpArrowKey = string('\ue013')
RightArrowKey = string('\ue014')
DownArrowKey = string('\ue015')
InsertKey = string('\ue016')
DeleteKey = string('\ue017')
SemicolonKey = string('\ue018')
EqualsKey = string('\ue019')
Numpad0Key = string('\ue01a')
Numpad1Key = string('\ue01b')
Numpad2Key = string('\ue01c')
Numpad3Key = string('\ue01d')
Numpad4Key = string('\ue01e')
Numpad5Key = string('\ue01f')
Numpad6Key = string('\ue020')
Numpad7Key = string('\ue021')
Numpad8Key = string('\ue022')
Numpad9Key = string('\ue023')
MultiplyKey = string('\ue024')
AddKey = string('\ue025')
SeparatorKey = string('\ue026')
SubstractKey = string('\ue027')
DecimalKey = string('\ue028')
DivideKey = string('\ue029')
F1Key = string('\ue031')
F2Key = string('\ue032')
F3Key = string('\ue033')
F4Key = string('\ue034')
F5Key = string('\ue035')
F6Key = string('\ue036')
F7Key = string('\ue037')
F8Key = string('\ue038')
F9Key = string('\ue039')
F10Key = string('\ue03a')
F11Key = string('\ue03b')
F12Key = string('\ue03c')
MetaKey = string('\ue03d')
)
/* Browser capabilities, see
http://code.google.com/p/selenium/wiki/JsonWireProtocol#Capabilities_JSON_Object
*/
type Capabilities map[string]interface{}
/* Build object, part of Status return. */
type Build struct {
Version, Revision, Time string
}
/* OS object, part of Status return. */
type OS struct {
Arch, Name, Version string
}
type Java struct {
Version string
}
/* Information retured by Status method. */
type Status struct {
Java Java
Build Build
OS OS
}
/* Point */
type Point struct {
X, Y int
}
/* Size */
type Size struct {
Width, Height int
}
/* Cookie */
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Path string `json:"path"`
Domain string `json:"domain"`
Secure bool `json:"secure"`
Expiry uint `json:"expiry"`
}
type WebDriver interface {
/* Status (info) on server */
Status() (*Status, error)
/* Start a new session, return session id */
NewSession() (string, error)
/* Current session id (empty string on none) */
SessionId() string
/* Current session capabilities */
Capabilities() (Capabilities, error)
/* Set the amount of time, in microseconds, that asynchronous scripts are permitted to run before they are aborted.
Note that Selenium/WebDriver timeouts are in milliseconds, timeout will be rounded to nearest millisecond.
*/
SetAsyncScriptTimeout(timeout time.Duration) error
/* Set the amount of time, in milliseconds, the driver should wait when searching for elements.
Note that Selenium/WebDriver timeouts are in milliseconds, timeout will be rounded to nearest millisecond.
*/
SetImplicitWaitTimeout(timeout time.Duration) error
// IME
/* List all available engines on the machine. */
AvailableEngines() ([]string, error)
/* Get the name of the active IME engine. */
ActiveEngine() (string, error)
/* Indicates whether IME input is active at the moment. */
IsEngineActivated() (bool, error)
/* De-activates the currently-active IME engine. */
DeactivateEngine() error
/* Make an engines active */
ActivateEngine(engine string) error
/* Quit (end) current session */
Quit() error
// Page information and manipulation
/* Return id of current window handle. */
CurrentWindowHandle() (string, error)
/* Return ids of current open windows. */
WindowHandles() ([]string, error)
/* Current url. */
CurrentURL() (string, error)
/* Page title. */
Title() (string, error)
/* Get page source. */
PageSource() (string, error)
/* Close current window. */
Close() error
/* Switch to frame, frame parameter can be name or id. */
SwitchFrame(frame string) error
/* Swtich to window. */
SwitchWindow(name string) error
/* Close window. */
CloseWindow(name string) error
/* Maximize window, if name is empty - will use current */
MaximizeWindow(name string) error
// Navigation
/* Open url. */
Get(url string) error
/* Move forward in history. */
Forward() error
/* Move backward in history. */
Back() error
/* Refresh page. */
Refresh() error
// Finding element(s)
/* Find, return one element. */
FindElement(by, value string) (WebElement, error)
/* Find, return list of elements. */
FindElements(by, value string) ([]WebElement, error)
/* Current active element. */
ActiveElement() (WebElement, error)
// Decoding element(s)
/* Decode a single element response. */
DecodeElement([]byte) (WebElement, error)
/* Decode a multi element response. */
DecodeElements([]byte) ([]WebElement, error)
// Cookies
/* Get all cookies */
GetCookies() ([]Cookie, error)
/* Add a cookies */
AddCookie(cookie *Cookie) error
/* Delete all cookies */
DeleteAllCookies() error
/* Delete a cookie */
DeleteCookie(name string) error
// Mouse
/* Click mouse button, button should be on of RightButton, MiddleButton or
LeftButton.
*/
Click(button int) error
/* Dobule click */
DoubleClick() error
/* Mouse button down */
ButtonDown() error
/* Mouse button up */
ButtonUp() error
// Misc
/* Send modifier key to active element.
modifier can be one of ShiftKey, ControlKey, AltKey, MetaKey.
*/
SendModifier(modifier string, isDown bool) error
/* Take a screenshot */
Screenshot() ([]byte, error)
// Alerts
/* Dismiss current alert. */
DismissAlert() error
/* Accept current alert. */
AcceptAlert() error
/* Current alert text. */
AlertText() (string, error)
/* Set current alert text. */
SetAlertText(text string) error
// Scripts
/* Execute a script. */
ExecuteScript(script string, args []interface{}) (interface{}, error)
/* Execute a script async. */
ExecuteScriptAsync(script string, args []interface{}) (interface{}, error)
/* Execute a script but don't JSON decode. */
ExecuteScriptRaw(script string, args []interface{}) ([]byte, error)
/* Execute a script async but don't JSON decode. */
ExecuteScriptAsyncRaw(script string, args []interface{}) ([]byte, error)
}
type WebElement interface {
// Manipulation
/* Click on element */
Click() error
/* Send keys (type) into element */
SendKeys(keys string) error
/* Submit */
Submit() error
/* Clear */
Clear() error
/* Move mouse to relative coordinates */
MoveTo(xOffset, yOffset int) error
// Finding
/* Find children, return one element. */
FindElement(by, value string) (WebElement, error)
/* Find children, return list of elements. */
FindElements(by, value string) ([]WebElement, error)
// Porperties
/* Element name */
TagName() (string, error)
/* Text of element */
Text() (string, error)
/* Check if element is selected. */
IsSelected() (bool, error)
/* Check if element is enabled. */
IsEnabled() (bool, error)
/* Check if element is displayed. */
IsDisplayed() (bool, error)
/* Get element attribute. */
GetAttribute(name string) (string, error)
/* Element location. */
Location() (*Point, error)
/* Element location once it has been scrolled into view. */
LocationInView() (*Point, error)
/* Element size */
Size() (*Size, error)
/* Get element CSS property value. */
CSSProperty(name string) (string, error)
}