watir 1.6.5 → 1.6.6.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +461 -326
- data/VERSION +1 -0
- data/bin/watir-console +6 -6
- data/lib/changes.rb +3 -3
- data/lib/license.rb +38 -38
- data/lib/readme.rb +140 -140
- data/lib/watir/WindowHelper.rb +49 -49
- data/lib/watir/camel_case.rb +66 -66
- data/lib/watir/clickJSDialog.rb +19 -19
- data/lib/watir/close_all.rb +37 -37
- data/lib/watir/collections.rb +392 -344
- data/lib/watir/container.rb +857 -815
- data/lib/watir/contrib/enabled_popup.rb +20 -20
- data/lib/watir/contrib/ie-new-process.rb +27 -27
- data/lib/watir/contrib/page_checker.rb +29 -29
- data/lib/watir/cookiemanager.rb +55 -55
- data/lib/watir/core.rb +28 -0
- data/lib/watir/core_ext.rb +17 -17
- data/lib/watir/datahandler.rb +107 -107
- data/lib/watir/dialog.rb +46 -46
- data/lib/watir/element.rb +351 -343
- data/lib/watir/element_collections.rb +97 -97
- data/lib/watir/form.rb +170 -170
- data/lib/watir/frame.rb +59 -59
- data/lib/watir/html_element.rb +22 -0
- data/lib/watir/ie-class.rb +1006 -1009
- data/lib/watir/ie-process.rb +39 -39
- data/lib/watir/ie.rb +70 -133
- data/lib/watir/image.rb +130 -130
- data/lib/watir/input_elements.rb +614 -572
- data/lib/watir/irb-history.rb +30 -30
- data/lib/watir/link.rb +64 -64
- data/lib/watir/locator.rb +200 -176
- data/lib/watir/logger.rb +19 -19
- data/lib/watir/modal_dialog.rb +122 -122
- data/lib/watir/module.rb +37 -0
- data/lib/watir/non_control_elements.rb +145 -145
- data/lib/watir/page-container.rb +116 -107
- data/lib/watir/popup.rb +29 -29
- data/lib/watir/process.rb +19 -19
- data/lib/watir/screen_capture.rb +115 -115
- data/lib/watir/setFileDialog.rb +16 -16
- data/lib/watir/table.rb +395 -362
- data/lib/watir/watir_simple.rb +475 -475
- data/lib/watir/win32.rb +35 -35
- data/lib/watir/win32ole.rb +14 -14
- data/lib/watir/winClicker.rb +496 -496
- data/rakefile.rb +70 -0
- data/unittests/all_tests.rb +10 -10
- data/unittests/buttons_xpath_test.rb +69 -69
- data/unittests/checkbox_test.rb +179 -179
- data/unittests/checkbox_xpath_test.rb +107 -107
- data/unittests/click_no_wait_test.rb +21 -0
- data/unittests/core_tests.rb +17 -17
- data/unittests/css_test.rb +42 -35
- data/unittests/defer_test.rb +46 -46
- data/unittests/dialog_test.rb +77 -77
- data/unittests/div2_xpath_test.rb +21 -21
- data/unittests/div_test.rb +188 -188
- data/unittests/div_xpath_test.rb +96 -96
- data/unittests/element_test.rb +49 -0
- data/unittests/errorchecker_test.rb +32 -22
- data/unittests/filefield_test.rb +39 -39
- data/unittests/filefield_xpath_test.rb +33 -33
- data/unittests/form_test.rb +280 -280
- data/unittests/form_xpath_test.rb +252 -252
- data/unittests/frame_test.rb +155 -155
- data/unittests/google_form_test.rb +15 -15
- data/unittests/html/JavascriptClick.html +39 -39
- data/unittests/html/blankpage.html +11 -11
- data/unittests/html/buttons1.html +40 -40
- data/unittests/html/checkboxes1.html +89 -89
- data/unittests/html/click_no_wait.html +14 -0
- data/unittests/html/complex_table.html +36 -36
- data/unittests/html/cssTest.html +42 -42
- data/unittests/html/depot_store.html +59 -59
- data/unittests/html/div.html +93 -93
- data/unittests/html/div_xml.html +20 -20
- data/unittests/html/fileupload.html +45 -45
- data/unittests/html/formTest1.html +38 -38
- data/unittests/html/forms2.html +44 -44
- data/unittests/html/forms3.html +131 -131
- data/unittests/html/forms4.html +27 -27
- data/unittests/html/frame_buttons.html +3 -3
- data/unittests/html/frame_links.html +3 -3
- data/unittests/html/frame_multi.html +4 -4
- data/unittests/html/google_india.html +119 -119
- data/unittests/html/iframeTest.html +12 -12
- data/unittests/html/iframeTest1.html +6 -6
- data/unittests/html/iframeTest2.html +5 -5
- data/unittests/html/images1.html +66 -66
- data/unittests/html/javascriptevents.html +35 -35
- data/unittests/html/link_pass.html +10 -10
- data/unittests/html/links1.html +38 -38
- data/unittests/html/links2.html +10 -10
- data/unittests/html/links_multi.html +14 -14
- data/unittests/html/list_matters.html +720 -720
- data/unittests/html/lists.html +17 -17
- data/unittests/html/map_test.html +31 -31
- data/unittests/html/modal_dialog.html +10 -10
- data/unittests/html/modal_dialog_launcher.html +11 -11
- data/unittests/html/nestedFrames.html +6 -6
- data/unittests/html/new_browser.html +16 -16
- data/unittests/html/pass.html +12 -12
- data/unittests/html/popups1.html +59 -59
- data/unittests/html/pre.html +27 -27
- data/unittests/html/radioButtons1.html +71 -71
- data/unittests/html/select_tealeaf.html +54 -54
- data/unittests/html/selectboxes1.html +52 -52
- data/unittests/html/simple_table.html +26 -26
- data/unittests/html/simple_table_buttons.html +104 -104
- data/unittests/html/simple_table_columns.html +76 -76
- data/unittests/html/table1.html +181 -181
- data/unittests/html/tableCell_using_xpath.html +19 -19
- data/unittests/html/table_and_tablerow_to_a.html +174 -0
- data/unittests/html/textarea.html +30 -30
- data/unittests/html/textfields1.html +88 -88
- data/unittests/html/textsearch.html +44 -44
- data/unittests/html/wallofcheckboxes.html +1003 -1003
- data/unittests/html/xpath_nbsp.html +12 -12
- data/unittests/ie_exists_test.rb +33 -33
- data/unittests/ie_mock.rb +94 -94
- data/unittests/ie_test.rb +51 -51
- data/unittests/images_test.rb +157 -157
- data/unittests/images_xpath_test.rb +91 -91
- data/unittests/links_multi_test.rb +48 -48
- data/unittests/links_test.rb +175 -175
- data/unittests/links_xpath_test.rb +39 -39
- data/unittests/lists_test.rb +32 -32
- data/unittests/map_test.rb +98 -98
- data/unittests/minmax_test.rb +31 -31
- data/unittests/navigate_test.rb +39 -39
- data/unittests/nbsp_xpath_test.rb +16 -16
- data/unittests/non_core_tests.rb +12 -12
- data/unittests/other/WindowLogonExample.rb +27 -27
- data/unittests/other/WindowLogonExtra.rb +6 -6
- data/unittests/other/all_tests_concurrent.rb +57 -57
- data/unittests/other/jscriptExtraAlert.rb +6 -6
- data/unittests/other/jscriptExtraConfirmCancel.rb +6 -6
- data/unittests/other/jscriptExtraConfirmOk.rb +6 -6
- data/unittests/other/jscriptPushButton.rb +6 -6
- data/unittests/other/jscript_test.rb +63 -63
- data/unittests/other/navigate_exception_test.rb +24 -24
- data/unittests/other/rexml_unit_test.rb +27 -27
- data/unittests/other/screen_capture_test.rb +54 -54
- data/unittests/other/testcase_method_order_test.rb +35 -35
- data/unittests/other/testcase_verify_test.rb +24 -24
- data/unittests/other/wait_until_test.rb +99 -99
- data/unittests/pagecontainstext_test.rb +69 -69
- data/unittests/parent_child_test.rb +43 -43
- data/unittests/perf_test.rb +20 -20
- data/unittests/popups_test.rb +43 -43
- data/unittests/pre_test.rb +53 -53
- data/unittests/radios_test.rb +212 -212
- data/unittests/radios_xpath_test.rb +101 -101
- data/unittests/security_setting_test.rb +23 -23
- data/unittests/selectbox_test.rb +148 -148
- data/unittests/selectbox_xpath_test.rb +113 -113
- data/unittests/setup.rb +87 -77
- data/unittests/speed_settings_test.rb +67 -67
- data/unittests/table_and_tablerow_to_a_test.rb +117 -0
- data/unittests/table_cell_using_xpath_test.rb +35 -35
- data/unittests/table_test.rb +376 -376
- data/unittests/table_xpath_test.rb +110 -110
- data/unittests/test_tests.rb +9 -9
- data/unittests/textarea_test.rb +92 -92
- data/unittests/textarea_xpath_test.rb +78 -78
- data/unittests/textfield_for_ch_char_test.rb +31 -31
- data/unittests/textfields_test.rb +218 -218
- data/unittests/textfields_xpath_test.rb +111 -111
- data/unittests/window_tests.rb +10 -10
- data/unittests/windows/attach_to_existing_window_test.rb +53 -53
- data/unittests/windows/attach_to_new_window_test.rb +83 -83
- data/unittests/windows/close_window_test.rb +20 -20
- data/unittests/windows/frame_links_test.rb +25 -25
- data/unittests/windows/ie-each_test.rb +47 -47
- data/unittests/windows/iedialog_test.rb +54 -54
- data/unittests/windows/js_events_test.rb +42 -55
- data/unittests/windows/modal_dialog_test.rb +128 -128
- data/unittests/windows/new_test.rb +57 -57
- data/unittests/windows/open_close_test.rb +18 -18
- data/unittests/windows/send_keys_test.rb +33 -33
- data/unittests/xpath_tests.rb +10 -10
- metadata +85 -31
- data/lib/watir/utils.rb +0 -20
- data/lib/watir/version.rb +0 -5
data/lib/watir/input_elements.rb
CHANGED
@@ -1,573 +1,615 @@
|
|
1
|
-
module Watir
|
2
|
-
|
3
|
-
class InputElement < Element
|
4
|
-
def locate
|
5
|
-
@o = @container.locate_input_element(@how, @what, self.class::INPUT_TYPES)
|
6
|
-
end
|
7
|
-
def initialize(container, how, what)
|
8
|
-
set_container container
|
9
|
-
@how = how
|
10
|
-
@what = what
|
11
|
-
super(nil)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
#
|
16
|
-
# Input: Select
|
17
|
-
#
|
18
|
-
|
19
|
-
# This class is the way in which select boxes are manipulated.
|
20
|
-
# Normally a user would not need to create this object as it is returned by the Watir::Container#select_list method
|
21
|
-
class SelectList < InputElement
|
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
|
-
def
|
160
|
-
@
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
def
|
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
|
-
# Raises
|
325
|
-
# Raises
|
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
|
-
@o.
|
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
|
-
def
|
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
|
-
class
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
end
|
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
|
-
|
1
|
+
module Watir
|
2
|
+
|
3
|
+
class InputElement < Element #:nodoc:all
|
4
|
+
def locate
|
5
|
+
@o = @container.locate_input_element(@how, @what, self.class::INPUT_TYPES)
|
6
|
+
end
|
7
|
+
def initialize(container, how, what)
|
8
|
+
set_container container
|
9
|
+
@how = how
|
10
|
+
@what = what
|
11
|
+
super(nil)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Input: Select
|
17
|
+
#
|
18
|
+
|
19
|
+
# This class is the way in which select boxes are manipulated.
|
20
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#select_list method
|
21
|
+
class SelectList < InputElement
|
22
|
+
#:stopdoc:
|
23
|
+
INPUT_TYPES = ["select-one", "select-multiple"]
|
24
|
+
#exposed to Option class
|
25
|
+
attr_accessor :o
|
26
|
+
#:startdoc:
|
27
|
+
|
28
|
+
# This method clears the selected items in the select box
|
29
|
+
def clear
|
30
|
+
assert_exists
|
31
|
+
highlight(:set)
|
32
|
+
wait = false
|
33
|
+
@o.each do |selectBoxItem|
|
34
|
+
if selectBoxItem.selected
|
35
|
+
selectBoxItem.selected = false
|
36
|
+
wait = true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
@container.wait if wait
|
40
|
+
highlight(:clear)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# This method selects an item, or items in a select box, by text.
|
45
|
+
# Raises NoValueFoundException if the specified value is not found.
|
46
|
+
# * item - the thing to select, string or reg exp
|
47
|
+
def select(item)
|
48
|
+
select_item_in_select_list(:text, item)
|
49
|
+
end
|
50
|
+
alias :set :select
|
51
|
+
|
52
|
+
# Selects an item, or items in a select box, by value.
|
53
|
+
# Raises NoValueFoundException if the specified value is not found.
|
54
|
+
# * item - the value of the thing to select, string, reg exp
|
55
|
+
def select_value(item)
|
56
|
+
select_item_in_select_list(:value, item)
|
57
|
+
end
|
58
|
+
|
59
|
+
# BUG: Should be private
|
60
|
+
# Selects something from the select box
|
61
|
+
# * name - symbol :value or :text - how we find an item in the select box
|
62
|
+
# * item - string or reg exp - what we are looking for
|
63
|
+
def select_item_in_select_list(attribute, value) #:nodoc:
|
64
|
+
assert_exists
|
65
|
+
highlight(:set)
|
66
|
+
found = false
|
67
|
+
|
68
|
+
value = value.to_s unless [Regexp, String].any? { |e| value.kind_of? e }
|
69
|
+
|
70
|
+
@container.log "Setting box #{@o.name} to #{attribute.inspect} => #{value.inspect}"
|
71
|
+
@o.each do |option| # items in the list
|
72
|
+
if value.matches(option.invoke(attribute.to_s))
|
73
|
+
if option.selected
|
74
|
+
found = true
|
75
|
+
break
|
76
|
+
else
|
77
|
+
option.selected = true
|
78
|
+
@o.fireEvent("onChange")
|
79
|
+
@container.wait
|
80
|
+
found = true
|
81
|
+
break
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
unless found
|
87
|
+
raise NoValueFoundException, "No option with #{attribute.inspect} of #{value.inspect} in this select element"
|
88
|
+
end
|
89
|
+
highlight(:clear)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Returns array of all text items displayed in a select box
|
93
|
+
# An empty array is returned if the select box has no contents.
|
94
|
+
# Raises UnknownObjectException if the select box is not found
|
95
|
+
def options
|
96
|
+
assert_exists
|
97
|
+
@container.log "There are #{@o.length} items"
|
98
|
+
returnArray = []
|
99
|
+
@o.each { |thisItem| returnArray << thisItem.text }
|
100
|
+
return returnArray
|
101
|
+
end
|
102
|
+
|
103
|
+
# Returns array of the selected text items in a select box
|
104
|
+
# Raises UnknownObjectException if the select box is not found.
|
105
|
+
def selected_options
|
106
|
+
assert_exists
|
107
|
+
returnArray = []
|
108
|
+
@container.log "There are #{@o.length} items"
|
109
|
+
@o.each do |thisItem|
|
110
|
+
if thisItem.selected
|
111
|
+
@container.log "Item (#{thisItem.text}) is selected"
|
112
|
+
returnArray << thisItem.text
|
113
|
+
end
|
114
|
+
end
|
115
|
+
return returnArray
|
116
|
+
end
|
117
|
+
|
118
|
+
# Does the SelectList include the specified option (text)?
|
119
|
+
def include? text_or_regexp
|
120
|
+
getAllContents.grep(text_or_regexp).size > 0
|
121
|
+
end
|
122
|
+
|
123
|
+
# Is the specified option (text) selected? Raises exception of option does not exist.
|
124
|
+
def selected? text_or_regexp
|
125
|
+
unless includes? text_or_regexp
|
126
|
+
raise UnknownObjectException, "Option #{text_or_regexp.inspect} not found."
|
127
|
+
end
|
128
|
+
|
129
|
+
getSelectedItems.grep(text_or_regexp).size > 0
|
130
|
+
end
|
131
|
+
|
132
|
+
# this method provides the access to the <tt><option></tt> item in select_list
|
133
|
+
#
|
134
|
+
# Usage example:
|
135
|
+
#
|
136
|
+
# Given the following html:
|
137
|
+
#
|
138
|
+
# <select id="gender">
|
139
|
+
# <option value="U">Unknown</option>
|
140
|
+
# <option value="M" selected>Male</option>
|
141
|
+
# <option value="F">Female</option>
|
142
|
+
# </select>
|
143
|
+
#
|
144
|
+
# get the +value+ attribute of option with visible +text+ 'Female'
|
145
|
+
# browser.select_list(:id, 'gender').option(:text, 'Female').value #=> 'F'
|
146
|
+
# or find out if the +value+ 'M' is selected
|
147
|
+
# browser.select_list(:id, 'gender').option(:value, 'M').selected #=> true
|
148
|
+
#
|
149
|
+
# * attribute - Symbol :value, :text or other attribute - how we find an item in the select box
|
150
|
+
# * value - string or reg exp - what we are looking for
|
151
|
+
def option(attribute, value)
|
152
|
+
assert_exists
|
153
|
+
Option.new(self, attribute, value)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
module OptionAccess
|
158
|
+
# text of SelectList#option
|
159
|
+
def text
|
160
|
+
@option.text
|
161
|
+
end
|
162
|
+
# value of SelectList#option
|
163
|
+
def value
|
164
|
+
@option.value
|
165
|
+
end
|
166
|
+
# return true if SelectList#option is selected, else false
|
167
|
+
def selected
|
168
|
+
@option.selected
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class OptionWrapper #:nodoc:all
|
173
|
+
include OptionAccess
|
174
|
+
def initialize(option)
|
175
|
+
@option = option
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
# An item in a select list.
|
180
|
+
# Normally a user would not need to create this object as it is returned by the Watir::SelectList#option method
|
181
|
+
class Option
|
182
|
+
include OptionAccess
|
183
|
+
include Watir::Exception
|
184
|
+
def initialize(select_list, attribute, value)
|
185
|
+
@select_list = select_list
|
186
|
+
@how = attribute
|
187
|
+
@what = value
|
188
|
+
@option = nil
|
189
|
+
|
190
|
+
unless [:text, :value, :label].include? attribute
|
191
|
+
raise MissingWayOfFindingObjectException,
|
192
|
+
"Option does not support attribute #{@how}"
|
193
|
+
end
|
194
|
+
@select_list.o.each do |option| # items in the list
|
195
|
+
if value.matches(option.invoke(attribute.to_s))
|
196
|
+
@option = option
|
197
|
+
break
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
def assert_exists
|
203
|
+
unless @option
|
204
|
+
raise UnknownObjectException,
|
205
|
+
"Unable to locate an option using #{@how} and #{@what}"
|
206
|
+
end
|
207
|
+
end
|
208
|
+
private :assert_exists
|
209
|
+
|
210
|
+
# select the accessed option in select_list
|
211
|
+
def select
|
212
|
+
assert_exists
|
213
|
+
@select_list.select_item_in_select_list(@how, @what)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
#
|
218
|
+
# Input: Button
|
219
|
+
#
|
220
|
+
|
221
|
+
# Returned by the Watir::Container#button method
|
222
|
+
class Button < InputElement
|
223
|
+
#:stopdoc:
|
224
|
+
INPUT_TYPES = ["button", "submit", "image", "reset"]
|
225
|
+
#:startdoc:
|
226
|
+
end
|
227
|
+
|
228
|
+
#
|
229
|
+
# Input: Text
|
230
|
+
#
|
231
|
+
|
232
|
+
# This class is the main class for Text Fields
|
233
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#text_field method
|
234
|
+
class TextField < InputElement
|
235
|
+
#:stopdoc:
|
236
|
+
INPUT_TYPES = ["text", "password", "textarea"]
|
237
|
+
|
238
|
+
def_wrap_guard :size
|
239
|
+
|
240
|
+
# Returns true or false if the text field is read only.
|
241
|
+
# Raises UnknownObjectException if the object can't be found.
|
242
|
+
def_wrap :readonly?, :readOnly
|
243
|
+
|
244
|
+
#:startdoc:
|
245
|
+
|
246
|
+
# return number of maxlength attribute
|
247
|
+
def maxlength
|
248
|
+
assert_exists
|
249
|
+
begin
|
250
|
+
ole_object.invoke('maxlength').to_i
|
251
|
+
rescue WIN32OLERuntimeError
|
252
|
+
0
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
|
257
|
+
def text_string_creator
|
258
|
+
n = []
|
259
|
+
n << "length:".ljust(TO_S_SIZE) + self.size.to_s
|
260
|
+
n << "max length:".ljust(TO_S_SIZE) + self.maxlength.to_s
|
261
|
+
n << "read only:".ljust(TO_S_SIZE) + self.readonly?.to_s
|
262
|
+
n
|
263
|
+
end
|
264
|
+
private :text_string_creator
|
265
|
+
|
266
|
+
def to_s
|
267
|
+
assert_exists
|
268
|
+
r = string_creator
|
269
|
+
r += text_string_creator
|
270
|
+
r.join("\n")
|
271
|
+
end
|
272
|
+
|
273
|
+
def assert_not_readonly #:nodoc:
|
274
|
+
if self.readonly?
|
275
|
+
raise ObjectReadOnlyException,
|
276
|
+
"Textfield #{@how} and #{@what} is read only."
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
# Returns true if the text field contents is matches the specified target,
|
281
|
+
# which can be either a string or a regular expression.
|
282
|
+
# Raises UnknownObjectException if the object can't be found
|
283
|
+
#--
|
284
|
+
# I vote for deprecating this
|
285
|
+
# we should use text_field().text.include?(some) or text.match(/some/) instead of this method
|
286
|
+
def verify_contains(target) #:nodoc:
|
287
|
+
assert_exists
|
288
|
+
if target.kind_of? String
|
289
|
+
return true if self.value == target
|
290
|
+
elsif target.kind_of? Regexp
|
291
|
+
return true if self.value.match(target) != nil
|
292
|
+
end
|
293
|
+
return false
|
294
|
+
end
|
295
|
+
|
296
|
+
# Drag the entire contents of the text field to another text field
|
297
|
+
# 19 Jan 2005 - It is added as prototype functionality, and may change
|
298
|
+
# * destination_how - symbol, :id, :name how we identify the drop target
|
299
|
+
# * destination_what - string or regular expression, the name, id, etc of the text field that will be the drop target
|
300
|
+
def drag_contents_to(destination_how, destination_what)
|
301
|
+
assert_exists
|
302
|
+
destination = @container.text_field(destination_how, destination_what)
|
303
|
+
unless destination.exists?
|
304
|
+
raise UnknownObjectException, "Unable to locate destination using #{destination_how } and #{destination_what } "
|
305
|
+
end
|
306
|
+
|
307
|
+
@o.focus
|
308
|
+
@o.select
|
309
|
+
value = self.value
|
310
|
+
|
311
|
+
@o.fireEvent("onSelect")
|
312
|
+
@o.fireEvent("ondragstart")
|
313
|
+
@o.fireEvent("ondrag")
|
314
|
+
destination.fireEvent("onDragEnter")
|
315
|
+
destination.fireEvent("onDragOver")
|
316
|
+
destination.fireEvent("ondrop")
|
317
|
+
|
318
|
+
@o.fireEvent("ondragend")
|
319
|
+
destination.value = destination.value + value.to_s
|
320
|
+
self.value = ""
|
321
|
+
end
|
322
|
+
|
323
|
+
# Clears the contents of the text box.
|
324
|
+
# Raises UnknownObjectException if the object can't be found
|
325
|
+
# Raises ObjectDisabledException if the object is disabled
|
326
|
+
# Raises ObjectReadOnlyException if the object is read only
|
327
|
+
def clear
|
328
|
+
assert_enabled
|
329
|
+
assert_not_readonly
|
330
|
+
|
331
|
+
highlight(:set)
|
332
|
+
|
333
|
+
@o.scrollIntoView
|
334
|
+
@o.focus
|
335
|
+
@o.select
|
336
|
+
@o.fireEvent("onSelect")
|
337
|
+
@o.value = ""
|
338
|
+
@o.fireEvent("onKeyPress")
|
339
|
+
@o.fireEvent("onChange")
|
340
|
+
@container.wait
|
341
|
+
highlight(:clear)
|
342
|
+
end
|
343
|
+
|
344
|
+
# Appends the specified string value to the contents of the text box.
|
345
|
+
# Raises UnknownObjectException if the object cant be found
|
346
|
+
# Raises ObjectDisabledException if the object is disabled
|
347
|
+
# Raises ObjectReadOnlyException if the object is read only
|
348
|
+
def append(value)
|
349
|
+
assert_enabled
|
350
|
+
assert_not_readonly
|
351
|
+
|
352
|
+
highlight(:set)
|
353
|
+
@o.scrollIntoView
|
354
|
+
@o.focus
|
355
|
+
type_by_character(value)
|
356
|
+
highlight(:clear)
|
357
|
+
end
|
358
|
+
|
359
|
+
# Sets the contents of the text box to the specified text value
|
360
|
+
# Raises UnknownObjectException if the object cant be found
|
361
|
+
# Raises ObjectDisabledException if the object is disabled
|
362
|
+
# Raises ObjectReadOnlyException if the object is read only
|
363
|
+
def set(value)
|
364
|
+
assert_enabled
|
365
|
+
assert_not_readonly
|
366
|
+
|
367
|
+
highlight(:set)
|
368
|
+
@o.scrollIntoView
|
369
|
+
if type_keys
|
370
|
+
@o.focus
|
371
|
+
@o.select
|
372
|
+
@o.fireEvent("onSelect")
|
373
|
+
@o.fireEvent("onKeyPress")
|
374
|
+
@o.value = ""
|
375
|
+
type_by_character(value)
|
376
|
+
@o.fireEvent("onChange")
|
377
|
+
@o.fireEvent("onBlur")
|
378
|
+
else
|
379
|
+
@o.value = limit_to_maxlength(value)
|
380
|
+
end
|
381
|
+
highlight(:clear)
|
382
|
+
end
|
383
|
+
|
384
|
+
# Sets the value of the text field directly.
|
385
|
+
# It causes no events to be fired or exceptions to be raised,
|
386
|
+
# so generally shouldn't be used.
|
387
|
+
# It is preffered to use the set method.
|
388
|
+
def value=(v)
|
389
|
+
assert_exists
|
390
|
+
@o.value = v.to_s
|
391
|
+
end
|
392
|
+
|
393
|
+
def requires_typing #:nodoc:
|
394
|
+
@type_keys = true
|
395
|
+
self
|
396
|
+
end
|
397
|
+
def abhors_typing #:nodoc:
|
398
|
+
@type_keys = false
|
399
|
+
self
|
400
|
+
end
|
401
|
+
|
402
|
+
private
|
403
|
+
|
404
|
+
# Type the characters in the specified string (value) one by one.
|
405
|
+
# It should not be used externally.
|
406
|
+
# * value - string - The string to enter into the text field
|
407
|
+
def type_by_character(value)
|
408
|
+
value = limit_to_maxlength(value)
|
409
|
+
characters_in(value) do |c|
|
410
|
+
sleep @container.typingspeed
|
411
|
+
@o.value = @o.value.to_s + c
|
412
|
+
@o.fireEvent("onKeyDown")
|
413
|
+
@o.fireEvent("onKeyPress")
|
414
|
+
@o.fireEvent("onKeyUp")
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
418
|
+
# Supports double-byte characters
|
419
|
+
def characters_in(value, &blk)
|
420
|
+
if RUBY_VERSION =~ /^1\.8/
|
421
|
+
index = 0
|
422
|
+
while index < value.length
|
423
|
+
len = value[index] > 128 ? 2 : 1
|
424
|
+
yield value[index, len]
|
425
|
+
index += len
|
426
|
+
end
|
427
|
+
else
|
428
|
+
value.each_char(&blk)
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
# Return the value (a string), limited to the maxlength of the element.
|
433
|
+
def limit_to_maxlength(value)
|
434
|
+
return value if @o.invoke('type') =~ /textarea/i # text areas don't have maxlength
|
435
|
+
if value.length > maxlength
|
436
|
+
value = value[0 .. maxlength - 1]
|
437
|
+
@container.log " Supplied string is #{value.length} chars, which exceeds the max length (#{maxlength}) of the field. Using value: #{value}"
|
438
|
+
end
|
439
|
+
value
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
# this class can be used to access hidden field objects
|
444
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#hidden method
|
445
|
+
class Hidden < TextField
|
446
|
+
#:stopdoc:
|
447
|
+
INPUT_TYPES = ["hidden"]
|
448
|
+
#:startdoc:
|
449
|
+
|
450
|
+
# set is overriden in this class, as there is no way to set focus to a hidden field
|
451
|
+
def set(n)
|
452
|
+
self.value = n
|
453
|
+
end
|
454
|
+
|
455
|
+
# override the append method, so that focus isnt set to the hidden object
|
456
|
+
def append(n)
|
457
|
+
self.value = self.value.to_s + n.to_s
|
458
|
+
end
|
459
|
+
|
460
|
+
# override the clear method, so that focus isnt set to the hidden object
|
461
|
+
def clear
|
462
|
+
self.value = ""
|
463
|
+
end
|
464
|
+
|
465
|
+
# this method will do nothing, as you cant set focus to a hidden field
|
466
|
+
def focus
|
467
|
+
end
|
468
|
+
|
469
|
+
# Hidden element is never visible - returns false.
|
470
|
+
def visible?
|
471
|
+
assert_exists
|
472
|
+
false
|
473
|
+
end
|
474
|
+
|
475
|
+
end
|
476
|
+
|
477
|
+
# For fields that accept file uploads
|
478
|
+
# Windows dialog is opened and handled in this case by autoit
|
479
|
+
# launching into a new process.
|
480
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#file_field method
|
481
|
+
class FileField < InputElement
|
482
|
+
#:stopdoc:
|
483
|
+
INPUT_TYPES = ["file"]
|
484
|
+
POPUP_TITLES = ['Choose file', 'Choose File to Upload']
|
485
|
+
#:startdoc:
|
486
|
+
|
487
|
+
# set the file location in the Choose file dialog in a new process
|
488
|
+
# will raise a WatirException if AutoIt is not correctly installed
|
489
|
+
def set(path_to_file)
|
490
|
+
assert_exists
|
491
|
+
require 'watir/windowhelper'
|
492
|
+
WindowHelper.check_autoit_installed
|
493
|
+
begin
|
494
|
+
Thread.new do
|
495
|
+
sleep 1 # it takes some time for popup to appear
|
496
|
+
|
497
|
+
system %{ruby -e '
|
498
|
+
require "win32ole"
|
499
|
+
|
500
|
+
@autoit = WIN32OLE.new("AutoItX3.Control")
|
501
|
+
time = Time.now
|
502
|
+
|
503
|
+
while (Time.now - time) < 15 # the loop will wait up to 15 seconds for popup to appear
|
504
|
+
#{POPUP_TITLES.inspect}.each do |popup_title|
|
505
|
+
next unless @autoit.WinWait(popup_title, "", 1) == 1
|
506
|
+
|
507
|
+
@autoit.ControlSetText(popup_title, "", "Edit1", #{path_to_file.inspect})
|
508
|
+
@autoit.ControlSend(popup_title, "", "Button2", "{ENTER}")
|
509
|
+
exit
|
510
|
+
end # each
|
511
|
+
end # while
|
512
|
+
'}
|
513
|
+
end.join(1)
|
514
|
+
rescue
|
515
|
+
raise Watir::Exception::WatirException, "Problem accessing Choose file dialog"
|
516
|
+
end
|
517
|
+
click
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
521
|
+
# This class contains common methods to both radio buttons and check boxes.
|
522
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#checkbox or by Watir::Container#radio methods
|
523
|
+
#--
|
524
|
+
# most of the methods available to this element are inherited from the Element class
|
525
|
+
class RadioCheckCommon < InputElement
|
526
|
+
def locate #:nodoc:
|
527
|
+
@o = @container.locate_input_element(@how, @what, self.class::INPUT_TYPES, @value)
|
528
|
+
end
|
529
|
+
def initialize(container, how, what, value=nil)
|
530
|
+
super container, how, what
|
531
|
+
@value = value
|
532
|
+
end
|
533
|
+
|
534
|
+
def inspect
|
535
|
+
'#<%s:0x%x located=%s how=%s what=%s value=%s>' % [self.class, hash*2, !!ole_object, @how.inspect, @what.inspect, @value.inspect]
|
536
|
+
end
|
537
|
+
|
538
|
+
# This method determines if a radio button or check box is set.
|
539
|
+
# Returns true if set/checked; false if not set/checked.
|
540
|
+
# Raises UnknownObjectException if its unable to locate an object.
|
541
|
+
def set?
|
542
|
+
assert_exists
|
543
|
+
return @o.checked
|
544
|
+
end
|
545
|
+
alias checked? set?
|
546
|
+
|
547
|
+
# This method is the common code for setting or clearing checkboxes and radio.
|
548
|
+
def set_clear_item(set)
|
549
|
+
@o.checked = set
|
550
|
+
@o.fireEvent("onClick")
|
551
|
+
@container.wait
|
552
|
+
end
|
553
|
+
private :set_clear_item
|
554
|
+
|
555
|
+
end
|
556
|
+
|
557
|
+
#--
|
558
|
+
# this class makes the docs better
|
559
|
+
#++
|
560
|
+
# This class is the watir representation of a radio button.
|
561
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#radio method
|
562
|
+
class Radio < RadioCheckCommon
|
563
|
+
INPUT_TYPES = ["radio"]
|
564
|
+
# This method clears a radio button. One of them will almost always be set.
|
565
|
+
# Returns true if set or false if not set.
|
566
|
+
# Raises UnknownObjectException if its unable to locate an object
|
567
|
+
# ObjectDisabledException IF THE OBJECT IS DISABLED
|
568
|
+
def clear
|
569
|
+
assert_enabled
|
570
|
+
highlight(:set)
|
571
|
+
set_clear_item(false)
|
572
|
+
highlight(:clear)
|
573
|
+
end
|
574
|
+
|
575
|
+
# This method sets the radio list item.
|
576
|
+
# Raises UnknownObjectException if it's unable to locate an object
|
577
|
+
# ObjectDisabledException if the object is disabled
|
578
|
+
def set
|
579
|
+
assert_enabled
|
580
|
+
highlight(:set)
|
581
|
+
@o.scrollIntoView
|
582
|
+
set_clear_item(true)
|
583
|
+
highlight(:clear)
|
584
|
+
end
|
585
|
+
|
586
|
+
end
|
587
|
+
|
588
|
+
# This class is the watir representation of a check box.
|
589
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#checkbox method
|
590
|
+
class CheckBox < RadioCheckCommon
|
591
|
+
INPUT_TYPES = ["checkbox"]
|
592
|
+
# This method checks or unchecks the checkbox.
|
593
|
+
# With no arguments supplied it sets the checkbox.
|
594
|
+
# Setting false argument unchecks/clears the checkbox.
|
595
|
+
# Raises UnknownObjectException if it's unable to locate an object
|
596
|
+
# ObjectDisabledException if the object is disabled
|
597
|
+
def set(value=true)
|
598
|
+
assert_enabled
|
599
|
+
highlight :set
|
600
|
+
unless @o.checked == value
|
601
|
+
set_clear_item value
|
602
|
+
end
|
603
|
+
highlight :clear
|
604
|
+
end
|
605
|
+
|
606
|
+
# Clears a check box.
|
607
|
+
# Raises UnknownObjectException if its unable to locate an object
|
608
|
+
# ObjectDisabledException if the object is disabled
|
609
|
+
def clear
|
610
|
+
set false
|
611
|
+
end
|
612
|
+
|
613
|
+
end
|
614
|
+
|
573
615
|
end
|