-
Notifications
You must be signed in to change notification settings - Fork 32
/
wire.py
1415 lines (1227 loc) · 62.8 KB
/
wire.py
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2008-2010 WebDriver committers
# Copyright 2008-2010 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Script for generating the wire protocol wiki documentation.
This script is probably overkill, but it ensures commands are documented with
consistent formatting.
Usage:
python trunk/wire.py > wiki/JsonWireProtocol.wiki
"""
class Resource(object):
def __init__(self, path):
self.path = path
self.methods = []
def __getattribute__(self, attr):
try:
return super(Resource, self).__getattribute__(attr)
except AttributeError, e:
if self.methods:
return self.methods[len(self.methods) - 1].__getattribute__(attr)
raise e
def Post(self, summary):
return self.AddMethod(Method(self, 'POST', summary))
def Get(self, summary):
return self.AddMethod(Method(self, 'GET', summary))
def Delete(self, summary):
return self.AddMethod(Method(self, 'DELETE', summary))
def AddMethod(self, method):
self.methods.append(method)
return self
def ToWikiString(self):
str = '=== %s ===\n' % self.path
for method in self.methods:
str = '%s%s' % (str, method.ToWikiString(self.path))
return str
def ToWikiTableString(self):
return ''.join(m.ToWikiTableString() for m in self.methods)
class SessionResource(Resource):
def AddMethod(self, method):
return (Resource.AddMethod(self, method).
AddUrlParameter(':sessionId',
'ID of the session to route the command to.'))
class ElementResource(SessionResource):
def AddMethod(self, method):
return (SessionResource.AddMethod(self, method).
AddUrlParameter(':id',
'ID of the element to route the command to.').
AddError('StaleElementReference',
'If the element referenced by `:id` is no longer attached '
'to the page\'s DOM.'))
def RequiresVisibility(self):
return self.AddError('ElementNotVisible',
'If the referenced element is not visible on the page '
'(either is hidden by CSS, has 0-width, or has 0-height)')
def RequiresEnabledState(self):
return self.AddError('InvalidElementState',
'If the referenced element is disabled.')
class Method(object):
def __init__(self, parent, method, summary):
self.parent = parent
self.method = method
self.summary = summary
self.url_parameters = []
self.json_parameters = []
self.javadoc_link = None
self.javadoc_comment = None
self.return_type = None
self.errors = {}
def AddUrlParameter(self, name, description):
self.url_parameters.append({
'name': name,
'desc': description})
return self.parent
def AddJsonParameter(self, name, type, description):
self.json_parameters.append({
'name': name,
'type': type,
'desc': description})
return self.parent
def AddError(self, type, summary):
self.errors[type] = {'type': type, 'summary': summary}
return self.parent
def SetJavadoc(self, link, comment):
if link is None:
self.javadoc_link = None
else:
self.javadoc_link = (
'http://selenium.googlecode.com/svn/trunk/docs/api/' + link)
self.javadoc_comment = comment
return self.parent
def SetReturnType(self, type, description):
self.return_type = {
'type': type,
'desc': description}
return self.parent
def _GetUrlParametersWikiString(self):
if not self.url_parameters:
return ''
return '''
<dd>
<dl>
<dt>*URL Parameters:*</dt>
%s
</dl>
</dd>''' % '\n'.join('<dd>`%s` - %s</dd>' %
(param['name'], param['desc'])
for param in self.url_parameters)
def _GetJsonParametersWikiString(self):
if not self.json_parameters:
return ''
return '''
<dd>
<dl>
<dt>*JSON Parameters:*</dt>
%s
</dl>
</dd>''' % '\n'.join('<dd>`%s` - `%s` %s</dd>' %
(param['name'], param['type'], param['desc'])
for param in self.json_parameters)
def _GetReturnTypeWikiString(self):
if not self.return_type:
return ''
type = ''
if self.return_type['type']:
type = '`%s` ' % self.return_type['type']
return '''
<dd>
<dl>
<dt>*Returns:*</dt>
<dd>%s%s</dd>
</dl>
</dd>''' % (type, self.return_type['desc'])
def _GetErrorWikiString(self):
if not self.errors.values():
return ''
return '''
<dd>
<dl>
<dt>*Potential Errors:*</dt>
%s
</dl>
</dd>''' % '\n'.join('<dd>`%s` - %s</dd>' %
(error['type'], error['summary'])
for error in self.errors.values())
def _GetJavadocWikiString(self):
if not self.javadoc_link:
return ''
return '''
<dd>
<dl>
<dt>*See Also:*</dt>
<dd>[%s %s]</dd>
</dl>
</dd>''' % (self.javadoc_link, self.javadoc_comment)
def ToWikiString(self, path):
return '''
<dl>
<dd>*%s %s*</dd>
<dd>
<dl>
<dd>%s</dd>%s%s%s%s%s
</dl>
</dd>
</dl>
''' % (self.method, path, self.summary,
self._GetUrlParametersWikiString(),
self._GetJsonParametersWikiString(),
self._GetReturnTypeWikiString(),
self._GetErrorWikiString(),
self._GetJavadocWikiString())
def ToWikiTableString(self):
javadoc = '_N/A_'
if self.javadoc_link:
javadoc = '[%s %s]' % (self.javadoc_link, self.javadoc_comment)
return '|| %s || %s || %s || %s ||\n' % (
self.method, self.parent.path,
self.summary[:self.summary.find('.') + 1].replace('\n', '').strip(),
javadoc)
def main():
resources = []
resources.append(
Resource('/session').
Post('''
Create a new session. The desired capabilities should be specified in a JSON
object with the following properties:
|| *Key* || *Type* || *Description* ||
|| browserName || string || The name of the browser to use; should be one of \
`{iphone|firefox|internet explorer|htmlunit|iphone|chrome}`||
|| version || string || The desired browser version. ||
|| javascriptEnabled || boolean || Whether the session should support \
!JavaScript. ||
|| platform || string || A key specifying the desired platform to launch the \
browser on. Should be one of `{WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANY}` ||
The server should attempt to create a session that most closely matches the \
desired capabilities.''').
AddJsonParameter('desiredCapabilities',
'{object}',
'A JSON object describing the desired capabilities for '
'the new session.').
SetJavadoc(None, 'n/a').
SetReturnType(None,
'A `303 See Other` redirect to `/session/:sessionId`, where'
' `:sessionId` is the ID of the newly created session.'))
resources.append(
SessionResource('/session/:sessionId').
Get('''Retrieve the capabilities of the specified session. The session's \
capabilities
will be returned in a JSON object with the following properties:
|| *Key* || *Type* || *Description* ||
|| browserName || string || The name of the browser to use; should be one of \
`{iphone|firefox|internet explorer|htmlunit|iphone|chrome}`||
|| version || string || The desired browser version. ||
|| javascriptEnabled || boolean || Whether the session should support \
!JavaScript. ||
|| platform || string || A key specifying the desired platform to launch the \
browser on. Should be one of `{WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANY}` ||
|| nativeEvents || boolean || Whether the browser has native events enabled. ||
''').
SetJavadoc(None, 'n/a').
SetReturnType('{object}',
'A JSON object with the session capabilities.').
Delete('Delete the session.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#quit()',
'WebDriver#quit()'))
resources.append(
SessionResource('/session/:sessionId/timeouts/async_script').
Post('''Set the amount of time, in milliseconds, that asynchronous \
scripts executed by `/session/:sessionId/execute_async` are permitted to run \
before they are aborted and a |Timeout| error is returned to the client.''').
AddJsonParameter('ms', '{number}',
'The amount of time, in milliseconds, that time-limited'
' commands are permitted to run.'))
resources.append(
SessionResource('/session/:sessionId/timeouts/implicit_wait').
Post('''Set the amount of time the driver should wait when searching for \
elements. When
searching for a single element, the driver should poll the page until an \
element is found or
the timeout expires, whichever occurs first. When searching for multiple \
elements, the driver
should poll the page until at least one element is found or the timeout \
expires, at which point
it should return an empty list.
If this command is never sent, the driver should default to an implicit wait of\
0ms.''').
AddJsonParameter('ms', '{number}',
'The amount of time to wait, in milliseconds. This value'
' has a lower bound of 0.').
SetJavadoc('java/org/openqa/selenium/WebDriver.Timeouts.html#'
'implicitlyWait(long,%20java.util.concurrent.TimeUnit)',
'WebDriver.Timeouts#implicitlyWait(long, TimeUnit)'))
resources.append(
SessionResource('/session/:sessionId/window_handle').
Get('Retrieve the current window handle.').
SetReturnType('{string}', 'The current window handle.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#getWindowHandle()',
'WebDriver#getWindowHandle()'))
resources.append(
SessionResource('/session/:sessionId/window_handles').
Get('Retrieve the list of all window handles available to the session.').
SetReturnType('{Array.<string>}', 'A list of window handles.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#getWindowHandles()',
'WebDriver#getWindowHandles()'))
resources.append(
SessionResource('/session/:sessionId/url').
Get('Retrieve the URL of the current page.').
SetReturnType('{string}', 'The current URL.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#getCurrentUrl()',
'WebDriver#getCurrentUrl()').
Post('Navigate to a new URL.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#get(java.lang.String)',
'WebDriver#get(String)').
AddJsonParameter('url', '{string}', 'The URL to navigate to.'))
resources.append(
SessionResource('/session/:sessionId/forward').
Post('Navigate forwards in the browser history, if possible.').
SetJavadoc('java/org/openqa/selenium/WebDriver.Navigation.html#forward()',
'WebDriver.Navigation#forward()'))
resources.append(
SessionResource('/session/:sessionId/back').
Post('Navigate backwards in the browser history, if possible.').
SetJavadoc('java/org/openqa/selenium/WebDriver.Navigation.html#back()',
'WebDriver.Navigation#back()'))
resources.append(
SessionResource('/session/:sessionId/refresh').
Post('Refresh the current page.').
SetJavadoc('java/org/openqa/selenium/WebDriver.Navigation.html#refresh()',
'WebDriver.Navigation#refresh()'))
resources.append(
SessionResource('/session/:sessionId/execute').
Post('''
Inject a snippet of !JavaScript into the page for execution in the context of \
the currently selected frame. The executed script is assumed to be \
synchronous and the result of evaluating the script is returned to the client.
The `script` argument defines the script to execute in the form of a \
function body. The value returned by that function will be returned to the \
client. The function will be invoked with the provided `args` array and the \
values may be accessed via the `arguments` object in the order specified.
Arguments may be any JSON-primitive, array, or JSON object. JSON objects that \
define a !WebElement reference will be converted to the corresponding DOM \
element. Likewise, any !WebElements in the script result will be returned to \
the client as !WebElement JSON objects.''').
AddJsonParameter('script', '{string}', 'The script to execute.').
AddJsonParameter('args', '{Array.<*>}', 'The script arguments.').
AddError('JavaScriptError', 'If the script throws an Error.').
AddError('StaleElementReference',
'If one of the script arguments is a !WebElement that is not '
'attached to the page\'s DOM.').
SetJavadoc('java/org/openqa/selenium/JavascriptExecutor.html#'
'executeScript(java.lang.String,%20java.lang.Object...)',
'JavascriptExecutor#executeScript(String, Object...)').
SetReturnType('{*}', 'The script result.'))
resources.append(
SessionResource('/session/:sessionId/execute_async').
Post('''
Inject a snippet of !JavaScript into the page for execution in the context of \
the currently selected frame. The executed script is assumed to be \
asynchronous and must signal that is done by invoking the provided callback, \
which is always provided as the final argument to the function. The value \
to this callback will be returned to the client.
Asynchronous script commands may not span page loads. If an `unload` event is \
fired while waiting for a script result, an error should be returned to the \
client.
The `script` argument defines the script to execute in teh form of a function \
body. The function will be invoked with the provided `args` array and the \
values may be accessed via the `arguments` object in the order specified. The \
final argument will always be a callback function that must be invoked to \
signal that the script has finished.
Arguments may be any JSON-primitive, array, or JSON object. JSON objects that \
define a !WebElement reference will be converted to the corresponding DOM \
element. Likewise, any !WebElements in the script result will be returned to \
the client as !WebElement JSON objects.''').
AddJsonParameter('script', '{string}', 'The script to execute.').
AddJsonParameter('args', '{Array.<*>}', 'The script arguments.').
AddError('JavaScriptError',
'If the script throws an Error or if an `unload` event is '
'fired while waiting for the script to finish.').
AddError('StaleElementReference',
'If one of the script arguments is a !WebElement that is not '
'attached to the page\'s DOM.').
AddError('Timeout',
'If the script callback is not invoked before the timout '
'expires. Timeouts are controlled by the '
'`/session/:sessionId/timeout/async_script` command.').
SetReturnType('{*}', 'The script result.'))
resources.append(
SessionResource('/session/:sessionId/screenshot').
Get('Take a screenshot of the current page.').
SetJavadoc('java/org/openqa/selenium/TakesScreenshot.html#'
'getScreenshotAs(org.openqa.selenium.OutputType)',
'TakesScreenshot#getScreenshotAs(OutputType)').
SetReturnType('{string}', 'The screenshot as a base64 encoded PNG.'))
resources.append(
SessionResource('/session/:sessionId/ime/available_engines').
Get('List all available engines on the machine. To use an engine, it has to be present in this list.').
AddError('ImeNotAvailableException', 'If the host does not support IME').
SetReturnType('{Array.<string>}', 'A list of available engines').
SetJavadoc('java/org/openqa/selenium/WebDriver.ImeHandler.html#getAvailableEngines()',
'WebDriver.ImeHandler#getAvailableEngines()'))
resources.append(
SessionResource('/session/:sessionId/ime/active_engine').
Get('Get the name of the active IME engine. The name string is platform specific.').
AddError('ImeNotAvailableException', 'If the host does not support IME').
SetReturnType('{string}', 'The name of the active IME engine.').
SetJavadoc('java/org/openqa/selenium/WebDriver.ImeHandler.html#getActiveEngine()',
'WebDriver.ImeHandler#getActiveEngine()'))
resources.append(
SessionResource('/session/:sessionId/ime/activated').
Get('Indicates whether IME input is active at the moment (not if it\'s available.').
AddError('ImeNotAvailableException', 'If the host does not support IME').
SetReturnType('{boolean}',
'true if IME input is available and currently active, false otherwise').
SetJavadoc('java/org/openqa/selenium/WebDriver.ImeHandler.html#isActivated()',
'WebDriver.ImeHandler#isActivated()'))
resources.append(
SessionResource('/session/:sessionId/ime/deactivate').
Post('De-activates the currently-active IME engine.').
AddError('ImeNotAvailableException', 'If the host does not support IME').
SetJavadoc('java/org/openqa/selenium/WebDriver.ImeHandler.html#deactivate()',
'WebDriver.ImeHandler#deactivate()'))
resources.append(
SessionResource('/session/:sessionId/ime/activate').
Post('''Make an engines that is available (appears on the list
returned by getAvailableEngines) active. After this call, the engine will
be added to the list of engines loaded in the IME daemon and the input sent
using sendKeys will be converted by the active engine.
Note that this is a platform-independent method of activating IME
(the platform-specific way being using keyboard shortcuts''').
AddJsonParameter('engine', '{string}',
'Name of the engine to activate.').
AddError('ImeActivationFailedException',
'If the engine is not available or if the activation fails for other reasons.').
AddError('ImeNotAvailableException', 'If the host does not support IME').
SetJavadoc('java/org/openqa/selenium/WebDriver.ImeHandler.html#activateEngine(java.lang.String)',
'WebDriver.ImeHandler#activateEngine(java.lang.String)'))
resources.append(
SessionResource('/session/:sessionId/frame').
Post('''Change focus to another frame on the page. If the frame ID is \
`null`, the server
should switch to the page's default content.''').
SetJavadoc('java/org/openqa/selenium/WebDriver.TargetLocator.html#frame(java.lang.String)',
'WebDriver.TargetLocator#frame(String)').
AddJsonParameter('id', '{string|number|null}',
'Identifier for the frame to change focus to.').
AddError('NoSuchFrame', 'If the frame specified by `id` cannot be found.'))
resources.append(
SessionResource('/session/:sessionId/window').
Post('''Change focus to another window. The window to change focus to \
may be specified by its
server assigned window handle, or by the value of its `name` attribute.''').
SetJavadoc('java/org/openqa/selenium/WebDriver.TargetLocator.html#window(java.lang.String)',
'WebDriver.TargetLocator#window(String)').
AddJsonParameter('name', '{string}', 'The window to change focus to.').
Delete('''Close the current window.''').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#close()',
'WebDriver#close()').
AddError('NoSuchWindow', 'If the window specified by `name` cannot be found.'))
resources.append(
SessionResource('/session/:sessionId/speed').
Get('''Get the current user input speed. The server should return one of
`{SLOW|MEDIUM|FAST}`. How these constants map to actual input speed is still \
browser specific and
not covered by the wire protocol.''').
SetReturnType('{string}', 'The current input speed mapped to one of `{SLOW|MEDIUM|FAST}`.').
SetJavadoc('java/org/openqa/selenium/WebDriver.Options.html#getSpeed()',
'WebDriver.Options#getSpeed()').
Post('''Set the user input speed. The speed should be specified as one of
`{SLOW|MEDIUM|FAST}`. How these constants map to actual input speed is still \
browser specific and
not covered by the wire protocol.''').
SetJavadoc('java/org/openqa/selenium/WebDriver.Options.html#setSpeed(org.openqa.selenium.Speed)',
'WebDriver.Options#setSpeed(Speed)').
AddJsonParameter('speed', '{string}',
'The new user input speed mapped to one of `{SLOW|MEDIUM|FAST}`.'))
resources.append(
SessionResource('/session/:sessionId/cookie').
Get('''Retrieve all cookies visible to the current page. Each cookie \
will be returned as a
JSON object with the following properties:
|| *Key* || *Type* || *Description* ||
|| name || string || The name of the cookie. ||
|| value || string || The cookie value. ||
|| path || string || (Optional) The cookie path.^1^ ||
|| domain || string || (Optional) The domain the cookie is visible to.^1^ ||
|| secure || boolean || (Optional) Whether the cookie is a secure cookie.^1^ ||
|| expiry || number || (Optional) When the cookie expires, specified in \
seconds since midnight, January 1, 1970 UTC.^1^ ||
^1^ Field should only be omitted if the server is incapable of providing the \
information.
''').
SetReturnType('{Array.<object>}', 'A list of cookies.').
SetJavadoc('java/org/openqa/selenium/WebDriver.Options.html#getCookies()',
'WebDriver.Options#getCookies()').
Post('''Set a cookie. The cookie should be specified as a JSON object \
with the following
properties:
|| *Key* || *Type* || *Description* ||
|| name || string || The name of the cookie; may not be an empty string. ||
|| value || string || The cookie value; may be an empty string. ||
|| path || string || (Optional) The cookie path; defaults to `"/"`. ||
|| domain || string || (Optional) The domain the cookie is visible to; \
defaults to the domain of the current page. ||
|| secure || boolean || (Optional) Whether the cookie is a secure cookie; \
defaults to false. ||
|| expiry || number || (Optional) When the cookie expires, in seconds since \
midnight, January 1, 1970 UTC; if not provided, the cookie should be set to \
expire when the browser is closed. ||
\n''').
AddJsonParameter('cookie', '{object}',
'A JSON object defining the cookie to add.').
SetJavadoc('java/org/openqa/selenium/WebDriver.Options.html#addCookie(org.openqa.selenium.Cookie)',
'WebDriver.Options#addCookie(Cookie)').
Delete('''Delete all cookies visible to the current page.''').
SetJavadoc('java/org/openqa/selenium/WebDriver.Options.html#deleteAllCookies()',
'WebDriver.Options#deleteAllCookies()').
AddError('InvalidCookieDomain',
'If the cookie\'s `domain` is not visible from the current page.').
AddError('UnableToSetCookie',
'If attempting to set a cookie on a page that does not support '
'cookies (e.g. pages with mime-type `text/plain`).'))
resources.append(
SessionResource('/session/:sessionId/cookie/:name').
Delete('''Delete the cookie with the given name. This command should be \
a no-op if there is no
such cookie visible to the current page.''').
AddUrlParameter(':name', 'The name of the cookie to delete.').
SetJavadoc('java/org/openqa/selenium/WebDriver.Options.html#getCookieNamed(java.lang.String)',
'WebDriver.Options#deleteCookieNamed(String)'))
resources.append(
SessionResource('/session/:sessionId/source').
Get('Get the current page source.').
SetReturnType('{string}', 'The current page source.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#getPageSource()',
'WebDriver#getPageSource()'))
resources.append(
SessionResource('/session/:sessionId/title').
Get('Get the current page title.').
SetReturnType('{string}', 'The current page title.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#getTitle()',
'WebDriver#getTitle()'))
resources.append(
SessionResource('/session/:sessionId/element').
Post('''Search for an element on the page, starting from the document \
root. The located element will be returned as a WebElement JSON object. \
The table below lists the locator strategies that each server should support. \
Each locator must return the first matching element located in the DOM.
|| *Strategy* || *Description* ||
|| class name || Returns an element whose class name contains the search \
value; compound class names are not permitted. ||
|| css || Returns an element matching a CSS selector. ||
|| id || Returns an element whose ID attribute matches the search value. ||
|| name || Returns an element whose NAME attribute matches the search value. ||
|| link text || Returns an anchor element whose visible text matches the \
search value. ||
|| partial link text || Returns an anchor element whose visible text \
partially matches the search value. ||
|| tag name || Returns an element whose tag name matches the search value. ||
|| xpath || Returns an element matching an XPath expression. ||
''').
AddJsonParameter('using', '{string}', 'The locator strategy to use.').
AddJsonParameter('value', '{string}', 'The The search target.').
SetReturnType('{ELEMENT:string}',
'A WebElement JSON object for the located element.').
AddError('XPathLookupError', 'If using XPath and the input expression is invalid.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#findElement(org.openqa.selenium.By)',
'WebDriver.#findElement(By)').
AddError('NoSuchElement', 'If the element cannot be found.'))
resources.append(
SessionResource('/session/:sessionId/elements').
Post('''Search for multiple elements on the page, starting from the \
document root. The located elements will be returned as a WebElement JSON \
objects. The table below lists the locator strategies that each server should \
support. Elements should be returned in the order located in the DOM.
|| *Strategy* || *Description* ||
|| class name || Returns all elements whose class name contains the search \
value; compound class names are not permitted. ||
|| css || Returns all elements matching a CSS selector. ||
|| id || Returns all elements whose ID attribute matches the search value. ||
|| name || Returns all elements whose NAME attribute matches the search value. ||
|| link text || Returns all anchor elements whose visible text matches the \
search value. ||
|| partial link text || Returns all anchor elements whose visible text \
partially matches the search value. ||
|| tag name || Returns all elements whose tag name matches the search value. ||
|| xpath || Returns all elements matching an XPath expression. ||
''').
AddJsonParameter('using', '{string}', 'The locator strategy to use.').
AddJsonParameter('value', '{string}', 'The The search target.').
SetReturnType('{Array.<{ELEMENT:string}>}',
'A list of WebElement JSON objects for the located elements.').
AddError('XPathLookupError', 'If using XPath and the input expression is invalid.').
SetJavadoc('java/org/openqa/selenium/WebDriver.html#findElements(org.openqa.selenium.By)',
'WebDriver.#findElements(By)'))
resources.append(
SessionResource('/session/:sessionId/element/active').
Post('Get the element on the page that currently has focus. The element will be returned as '
'a WebElement JSON object.').
SetReturnType('{ELEMENT:string}', 'A WebElement JSON object for the active element.').
SetJavadoc('java/org/openqa/selenium/WebDriver.TargetLocator.html#activeElement()',
'WebDriver.TargetLocator#activeElement()'))
resources.append(
ElementResource('/session/:sessionId/element/:id').
Get('''Describe the identified element.
*Note:* This command is reserved for future use; its return type is currently \
undefined.'''))
resources.append(
ElementResource('/session/:sessionId/element/:id/element').
Post('''Search for an element on the page, starting from the identified \
element. The located element will be returned as a WebElement JSON object. \
The table below lists the locator strategies that each server should support. \
Each locator must return the first matching element located in the DOM.
|| *Strategy* || *Description* ||
|| class name || Returns an element whose class name contains the search \
value; compound class names are not permitted. ||
|| css || Returns an element matching a CSS selector. ||
|| id || Returns an element whose ID attribute matches the search value. ||
|| name || Returns an element whose NAME attribute matches the search value. ||
|| link text || Returns an anchor element whose visible text matches the \
search value. ||
|| partial link text || Returns an anchor element whose visible text \
partially matches the search value. ||
|| tag name || Returns an element whose tag name matches the search value. ||
|| xpath || Returns an element matching an XPath expression. The provided \
XPath expression must be applied to the server "as is"; if the expression is \
not relative to the element root, the server should not modify it. \
Consequently, an XPath query may return elements not contained in the root \
element's subtree. ||
''').
AddJsonParameter('using', '{string}', 'The locator strategy to use.').
AddJsonParameter('value', '{string}', 'The The search target.').
SetReturnType('{ELEMENT:string}',
'A WebElement JSON object for the located element.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#findElement(org.openqa.selenium.By)',
'WebElement#findElement(By)').
AddError('NoSuchElement', 'If the element cannot be found.').
AddError('XPathLookupError', 'If using XPath and the input expression is invalid.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/elements').
Post('''Search for multiple elements on the page, starting from the \
identified element. The located elements will be returned as a WebElement \
JSON objects. The table below lists the locator strategies that each server \
should support. Elements should be returned in the order located in the DOM.
|| *Strategy* || *Description* ||
|| class name || Returns all elements whose class name contains the search \
value; compound class names are not permitted. ||
|| css || Returns all elements matching a CSS selector. ||
|| id || Returns all elements whose ID attribute matches the search value. ||
|| name || Returns all elements whose NAME attribute matches the search value. ||
|| link text || Returns all anchor elements whose visible text matches the \
search value. ||
|| partial link text || Returns all anchor elements whose visible text \
partially matches the search value. ||
|| tag name || Returns all elements whose tag name matches the search value. ||
|| xpath || Returns all elements matching an XPath expression. The provided \
XPath expression must be applied to the server "as is"; if the expression is \
not relative to the element root, the server should not modify it. \
Consequently, an XPath query may return elements not contained in the root \
element's subtree. ||
''').
AddJsonParameter('using', '{string}', 'The locator strategy to use.').
AddJsonParameter('value', '{string}', 'The The search target.').
SetReturnType('{Array.<{ELEMENT:string}>}',
'A list of WebElement JSON objects for the located elements.').
AddError('XPathLookupError', 'If using XPath and the input expression is invalid.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#findElements(org.openqa.selenium.By)',
'WebElement#findElements(By)'))
resources.append(
ElementResource('/session/:sessionId/element/:id/click').
Post('Click on an element.').
RequiresVisibility().
SetJavadoc('java/org/openqa/selenium/WebElement.html#click()',
'WebElement#click()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/submit').
Post('Submit a `FORM` element. The submit command may also be applied to any element that is '
'a descendant of a `FORM` element.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#submit()',
'WebElement#submit()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/text').
Get('Returns the visible text for the element.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#getText()',
'WebElement#getText()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/value').
Get('Query for the value of an element, as determined by its `value` attribute.').
SetReturnType('{string|null}',
'The element\'s value, or `null` if it does not have a `value` attribute.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#getValue()',
'WebElement#getValue()').
Post('''Send a sequence of key strokes to an element.
Any UTF-8 character may be specified, however, if the server does not support \
native key events, it should simulate key strokes for a standard US keyboard \
layout. The Unicode [http://unicode.org/faq/casemap_charprop.html#8 Private Use\
Area] code points, 0xE000-0xF8FF, are used to represent pressable, non-text \
keys (see table below).
<table cellspacing=5 cellpadding=5>
<tbody><tr><td valign=top>
|| *Key* || *Code* ||
|| NULL || U+E000 ||
|| Cancel || U+E001 ||
|| Help || U+E002 ||
|| Back space || U+E003 ||
|| Tab || U+E004 ||
|| Clear || U+E005 ||
|| Return^1^ || U+E006 ||
|| Enter^1^ || U+E007 ||
|| Shift || U+E008 ||
|| Control || U+E009 ||
|| Alt || U+E00A ||
|| Pause || U+E00B ||
|| Escape || U+E00C ||
</td><td valign=top>
|| *Key* || *Code* ||
|| Space || U+E00D ||
|| Pageup || U+E00E ||
|| Pagedown || U+E00F ||
|| End || U+E010 ||
|| Home || U+E011 ||
|| Left arrow || U+E012 ||
|| Up arrow || U+E013 ||
|| Right arrow || U+E014 ||
|| Down arrow || U+E015 ||
|| Insert || U+E016 ||
|| Delete || U+E017 ||
|| Semicolon || U+E018 ||
|| Equals || U+E019 ||
</td><td valign=top>
|| *Key* || *Code* ||
|| Numpad 0 || U+E01A ||
|| Numpad 1 || U+E01B ||
|| Numpad 2 || U+E01C ||
|| Numpad 3 || U+E01D ||
|| Numpad 4 || U+E01E ||
|| Numpad 5 || U+E01F ||
|| Numpad 6 || U+E020 ||
|| Numpad 7 || U+E021 ||
|| Numpad 8 || U+E022 ||
|| Numpad 9 || U+E023 ||
</td><td valign=top>
|| *Key* || *Code* ||
|| Multiply || U+E024 ||
|| Add || U+E025 ||
|| Separator || U+E026 ||
|| Subtract || U+E027 ||
|| Decimal || U+E028 ||
|| Divide || U+E029 ||
</td><td valign=top>
|| *Key* || *Code* ||
|| F1 || U+E031 ||
|| F2 || U+E032 ||
|| F3 || U+E033 ||
|| F4 || U+E034 ||
|| F5 || U+E035 ||
|| F6 || U+E036 ||
|| F7 || U+E037 ||
|| F8 || U+E038 ||
|| F9 || U+E039 ||
|| F10 || U+E03A ||
|| F11 || U+E03B ||
|| F12 || U+E03C ||
|| Command/Meta || U+E03D ||
</td></tr>
<tr><td colspan=5>^1^ The return key is _not the same_ as the \
[http://en.wikipedia.org/wiki/Enter_key enter key].</td></tr></tbody></table>
The server must process the key sequence as follows:
* Each key that appears on the keyboard without requiring modifiers are sent \
as a keydown followed by a key up.
* If the server does not support native events and must simulate key strokes \
with !JavaScript, it must generate keydown, keypress, and keyup events, in that\
order. The keypress event should only be fired when the corresponding key is \
for a printable character.
* If a key requires a modifier key (e.g. "!" on a standard US keyboard), the \
sequence is: <var>modifier</var> down, <var>key</var> down, <var>key</var> up, \
<var>modifier</var> up, where <var>key</var> is the ideal unmodified key value \
(using the previous example, a "1").
* Modifier keys (Ctrl, Shift, Alt, and Command/Meta) are assumed to be \
"sticky"; each modifier should be held down (e.g. only a keydown event) until \
either the modifier is encountered again in the sequence, or the `NULL` \
(U+E000) key is encountered.
* Each key sequence is terminated with an implicit `NULL` key. Subsequently, \
all depressed modifier keys must be released (with corresponding keyup events) \
at the end of the sequence.
''').
RequiresVisibility().
AddJsonParameter('value', '{Array.<string>}',
'The sequence of keys to type. An array must be provided. '
'The server should flatten the array items to a single '
'string to be typed.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#sendKeys(java.lang.CharSequence...)',
'WebElement#sendKeys(CharSequence...)'))
resources.append(
SessionResource('/session/:sessionId/modifier').
Post('Send an event to the active element to depress or release a '
'modifier key.').
AddJsonParameter('value', '{string}',
'The modifier key event to be sent. This key must be one'
' Ctrl, Shift, Alt, or Command/Meta, as defined by the '
'[JsonWireProtocol#/session/:sessionId/element/:id/value'
' send keys] command.').
AddJsonParameter('isdown', '{boolean}',
'Whether to generate a key down or key up.').
SetJavadoc('java/org/openqa/selenium/Keyboard.html#pressKey(org.openqa.selenium.Keys)',
'pressKey(org.openqa.selenium.Keys)'))
resources.append(
ElementResource('/session/:sessionId/element/:id/name').
Get('Query for an element\'s tag name.').
SetReturnType('{string}', 'The element\'s tag name, as a lowercase string.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#getTagName()',
'WebElement#getTagName()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/clear').
Post('Clear a `TEXTAREA` or `text INPUT` element\'s value.').
RequiresVisibility().
RequiresEnabledState().
SetJavadoc('java/org/openqa/selenium/WebElement.html#clear()',
'WebElement#clear()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/selected').
Get('Determine if an `OPTION` element, or an `INPUT` element of type `checkbox` or '
'`radiobutton` is currently selected.').
SetReturnType('{boolean}', 'Whether the element is selected.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#isSelected()',
'WebElement#isSelected()').
Post('Select an `OPTION` element, or an `INPUT` element of type `checkbox` or `radiobutton`.').
RequiresVisibility().
RequiresEnabledState().
AddError('ElementIsNotSelectable', 'If the referenced element cannot be selected.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#setSelected()',
'WebElement#setSelected()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/toggle').
Post('Toggle whether an `OPTION` element, or an `INPUT` element of type `checkbox` or '
'`radiobutton` is currently selected.').
RequiresVisibility().
RequiresEnabledState().
AddError('ElementIsNotSelectable', 'If the referenced element cannot be selected.').
SetReturnType('{boolean}', 'Whether the element is selected after toggling its state.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#toggle()',
'WebElement#toggle()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/enabled').
Get('Determine if an element is currently enabled.').
SetReturnType('{boolean}', 'Whether the element is enabled.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#isEnabled()',
'WebElement#isEnabled()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/attribute/:name').
Get('Get the value of an element\'s attribute.').
SetReturnType('{string|null}',
'The value of the attribute, or null if it is not set on the element.').
SetJavadoc('java/org/openqa/selenium/WebElement.html#getAttribute(java.lang.String)',
'WebElement#getAttribute(String)'))
resources.append(
ElementResource('/session/:sessionId/element/:id/equals/:other').
Get('Test if two element IDs refer to the same DOM element.').
AddUrlParameter(':other', 'ID of the element to compare against.').
SetReturnType('{boolean}', 'Whether the two IDs refer to the same element.').
AddError('StaleElementReference',
'If either the element refered to by `:id` or `:other` is no '
'longer attached to the page\'s DOM.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/displayed').
Get('Determine if an element is currently displayed.').
SetReturnType('{boolean}', 'Whether the element is displayed.').
SetJavadoc('java/org/openqa/selenium/RenderedWebElement.html#isDisplayed()',
'RenderedWebElement#isDisplayed()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/location').
Get('Determine an element\'s location on the page. The point `(0, 0)` refers to the '
'upper-left corner of the page. The element\'s coordinates are returned as a JSON object '
'with `x` and `y` properties.').
SetReturnType('{x:number, y:number}', 'The X and Y coordinates for the element on the page.').
SetJavadoc('java/org/openqa/selenium/RenderedWebElement.html#getLocation()',
'RenderedWebElement#getLocation()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/location_in_view').
Get('''Determine an element\'s location on the screen once it has been \
scrolled into view.
*Note:* This is considered an internal command and should *only* be used to \
determine an element's
location for correctly generating native events.''').
SetReturnType('{x:number, y:number}', 'The X and Y coordinates for the element.'))
resources.append(
ElementResource('/session/:sessionId/element/:id/size').
Get('Determine an element\'s size in pixels. The size will be returned as a JSON object '
' with `width` and `height` properties.').
SetReturnType('{width:number, height:number}', 'The width and height of the element, in pixels.').
SetJavadoc('java/org/openqa/selenium/RenderedWebElement.html#getSize()',
'RenderedWebElement#getSize()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/css/:propertyName').
Get('Query the value of an element\'s computed CSS property. The CSS property to query should'
' be specified using the CSS property name, *not* the !JavaScript property name (e.g. '
'`background-color` instead of `backgroundColor`).').
SetReturnType('{string}', 'The value of the specified CSS property.').
SetJavadoc('java/org/openqa/selenium/RenderedWebElement.html#getValueOfCssProperty(java.lang.String)',
'RenderedWebElement#getValueOfCssProperty(String)'))
resources.append(
ElementResource('/session/:sessionId/element/:id/hover').
Post('Move the mouse over an element.').
RequiresVisibility().
RequiresEnabledState().
SetJavadoc('java/org/openqa/selenium/RenderedWebElement.html#hover()',
'RenderedWebElement#hover()'))
resources.append(
ElementResource('/session/:sessionId/element/:id/drag').
Post('Drag and drop an element. The distance to drag an element should be specified relative '
'to the upper-left corner of the page.').
RequiresVisibility().
RequiresEnabledState().
AddJsonParameter('x', '{number}',
'The number of pixels to drag the element in the horizontal direction. '