firewatir 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/MozillaBaseElement.rb +1778 -0
  2. data/container.rb +889 -0
  3. data/firewatir/exceptions.rb +44 -0
  4. data/firewatir/testUnitAddons.rb +8 -0
  5. data/firewatir.rb +1130 -0
  6. data/htmlelements.rb +2277 -0
  7. data/unittests/attach_to_new_window_test.rb +34 -0
  8. data/unittests/bug_fixes_test.rb +188 -0
  9. data/unittests/buttons_test.rb +215 -0
  10. data/unittests/buttons_xpath_test.rb +87 -0
  11. data/unittests/checkbox_test.rb +154 -0
  12. data/unittests/checkbox_xpath_test.rb +107 -0
  13. data/unittests/div_test.rb +274 -0
  14. data/unittests/filefield_test.rb +45 -0
  15. data/unittests/filefield_xpath_test.rb +35 -0
  16. data/unittests/form_test.rb +307 -0
  17. data/unittests/frame_test.rb +151 -0
  18. data/unittests/hidden_test.rb +85 -0
  19. data/unittests/hidden_xpath_test.rb +72 -0
  20. data/unittests/html/JavascriptClick.html +42 -0
  21. data/unittests/html/blankpage.html +12 -0
  22. data/unittests/html/buttons1.html +61 -0
  23. data/unittests/html/checkboxes1.html +71 -0
  24. data/unittests/html/complex_table.html +36 -0
  25. data/unittests/html/cssTest.html +42 -0
  26. data/unittests/html/div.html +72 -0
  27. data/unittests/html/div_xml.html +21 -0
  28. data/unittests/html/fileupload.html +45 -0
  29. data/unittests/html/formTest1.html +39 -0
  30. data/unittests/html/forms2.html +45 -0
  31. data/unittests/html/forms3.html +132 -0
  32. data/unittests/html/forms4.html +27 -0
  33. data/unittests/html/frame_buttons.html +4 -0
  34. data/unittests/html/frame_links.html +4 -0
  35. data/unittests/html/frame_multi.html +5 -0
  36. data/unittests/html/iframeTest.html +15 -0
  37. data/unittests/html/iframeTest1.html +14 -0
  38. data/unittests/html/iframeTest2.html +6 -0
  39. data/unittests/html/images/1.gif +0 -0
  40. data/unittests/html/images/2.GIF +0 -0
  41. data/unittests/html/images/3.GIF +0 -0
  42. data/unittests/html/images/button.jpg +0 -0
  43. data/unittests/html/images/circle.jpg +0 -0
  44. data/unittests/html/images/minus.GIF +0 -0
  45. data/unittests/html/images/originaltriangle.jpg +0 -0
  46. data/unittests/html/images/plus.gif +0 -0
  47. data/unittests/html/images/square.jpg +0 -0
  48. data/unittests/html/images/triangle.jpg +0 -0
  49. data/unittests/html/images1.html +67 -0
  50. data/unittests/html/javascriptevents.html +35 -0
  51. data/unittests/html/link_pass.html +11 -0
  52. data/unittests/html/links1.html +42 -0
  53. data/unittests/html/links2.html +11 -0
  54. data/unittests/html/modal_dialog.html +8 -0
  55. data/unittests/html/modal_dialog_launcher.html +12 -0
  56. data/unittests/html/nestedFrames.html +6 -0
  57. data/unittests/html/new_browser.html +17 -0
  58. data/unittests/html/pass.html +10 -0
  59. data/unittests/html/popups1.html +60 -0
  60. data/unittests/html/pre.html +28 -0
  61. data/unittests/html/radioButtons1.html +71 -0
  62. data/unittests/html/redirect.html +10 -0
  63. data/unittests/html/redirect1.html +9 -0
  64. data/unittests/html/redirect2.html +9 -0
  65. data/unittests/html/redirect3.html +9 -0
  66. data/unittests/html/select_tealeaf.html +54 -0
  67. data/unittests/html/selectboxes1.html +55 -0
  68. data/unittests/html/simple_table.html +26 -0
  69. data/unittests/html/simple_table_buttons.html +104 -0
  70. data/unittests/html/simple_table_columns.html +74 -0
  71. data/unittests/html/table1.html +165 -0
  72. data/unittests/html/tableCell_using_xpath.html +19 -0
  73. data/unittests/html/textarea.html +30 -0
  74. data/unittests/html/textfields1.html +62 -0
  75. data/unittests/html/textsearch.html +44 -0
  76. data/unittests/images_test.rb +204 -0
  77. data/unittests/images_xpath_test.rb +118 -0
  78. data/unittests/iostring.rb +30 -0
  79. data/unittests/iostring_test.rb +48 -0
  80. data/unittests/javascript_test.rb +71 -0
  81. data/unittests/links_test.rb +230 -0
  82. data/unittests/links_xpath_test.rb +79 -0
  83. data/unittests/mozilla_all_tests.rb +18 -0
  84. data/unittests/pre_test.rb +74 -0
  85. data/unittests/radios_test.rb +166 -0
  86. data/unittests/radios_xpath_test.rb +101 -0
  87. data/unittests/redirect_test.rb +40 -0
  88. data/unittests/selectbox_test.rb +141 -0
  89. data/unittests/selectbox_xpath_test.rb +127 -0
  90. data/unittests/setup.rb +35 -0
  91. data/unittests/table_test.rb +372 -0
  92. data/unittests/table_xpath_test.rb +184 -0
  93. data/unittests/textfields_test.rb +230 -0
  94. data/unittests/textfields_xpath_test.rb +112 -0
  95. metadata +144 -0
data/htmlelements.rb ADDED
@@ -0,0 +1,2277 @@
1
+ =begin
2
+ #
3
+ # Contains class definition of each HTML element that FireWatir can address.
4
+ # All classes inehrit from Element base class defined in MozillaBaseElement.rb
5
+ # User should not create instance of these classes. As they are created by using
6
+ # container#element methods. For e.g. container#button, container#link etc.
7
+ #
8
+ # All the methods in the classes first checks if element exists or not. If not then
9
+ # raises UnknownObjectException.
10
+ #
11
+ =end
12
+
13
+ #
14
+ # Description:
15
+ # Class for Frame element.
16
+ #
17
+ class Frame < Element
18
+
19
+ attr_accessor :element_name
20
+ #
21
+ # Description:
22
+ # Initializes the instance of frame or iframe object.
23
+ #
24
+ # Input:
25
+ # - how - Attribute to identify the frame element.
26
+ # - what - Value of that attribute.
27
+ #
28
+ def initialize(container, how, what)
29
+ @how = how
30
+ @what = what
31
+ @container = container
32
+ end
33
+
34
+ def locate
35
+ if(@how == :jssh_name)
36
+ @element_name = @what
37
+ else
38
+ @element_name = locate_frame(@how, @what)
39
+ end
40
+ #puts @element_name
41
+ @o = self
42
+
43
+ unless @element_name
44
+ raise UnknownFrameException, "Unable to locate a frame using #{@how} and #{@what}. "
45
+ end
46
+ end
47
+
48
+ def html
49
+ assert_exists
50
+ get_frame_html
51
+ end
52
+ end
53
+
54
+ #
55
+ # Description:
56
+ # Class for Form element.
57
+ #
58
+ class Form < Element
59
+
60
+ attr_accessor :element_name
61
+ #
62
+ # Description:
63
+ # Initializes the instance of form object.
64
+ #
65
+ # Input:
66
+ # - how - Attribute to identify the form element.
67
+ # - what - Value of that attribute.
68
+ #
69
+ def initialize(container, how, what)
70
+ @how = how
71
+ @what = what
72
+ @container = container
73
+ end
74
+
75
+ def locate
76
+ # Get form using xpath.
77
+ if @how == :jssh_name
78
+ @element_name = @what
79
+ elsif @how == :xpath
80
+ @element_name = element_by_xpath(container, @what)
81
+ else
82
+ @element_name = locate_tagged_element("form",@how, @what)
83
+ end
84
+ @o = self
85
+ end
86
+
87
+ #
88
+ # Description:
89
+ # Submit the form. Equivalent to pressing Enter or Return to submit a form.
90
+ #
91
+ def submit
92
+ assert_exists
93
+ submit_form
94
+ @o.wait
95
+ end
96
+
97
+ end # class Form
98
+
99
+ #
100
+ # Description:
101
+ # Base class containing items that are common between the span, div, label, p and pre classes.
102
+ #
103
+ class NonControlElement < Element
104
+
105
+ attr_accessor :element_name
106
+ #def get_element_name
107
+ # return @element_name
108
+ #end
109
+ #
110
+ # Description:
111
+ # Locate the element on the page. Element can be a span, div, label, p or pre HTML tag.
112
+ #
113
+ def locate
114
+ if(@how == :jssh_name)
115
+ @element_name = @what
116
+ elsif @how == :xpath
117
+ @element_name = element_by_xpath(@container, @what)
118
+ else
119
+ @element_name = locate_tagged_element(self.class::TAG, @how, @what)
120
+ end
121
+ @o = self
122
+ end
123
+
124
+ #
125
+ # Description:
126
+ # Initializes the instance of element object. Element can be a span, div, label, p or pre HTML element.
127
+ #
128
+ # Input:
129
+ # - how - Attribute to identify the element.
130
+ # - what - Value of that attribute.
131
+ #
132
+ def initialize(container, how, what)
133
+ #@element = Element.new(nil)
134
+ @how = how
135
+ @what = what
136
+ @container = container
137
+ @o = nil
138
+ end
139
+
140
+ #
141
+ # Description:
142
+ # Creates string of properties of the object.
143
+ #
144
+ def to_s(attributes = nil)
145
+ assert_exists
146
+ hash_properties = {"text"=>"innerHTML"}
147
+ hash_properties.update(attributes) if attributes != nil
148
+ r = super(hash_properties)
149
+ #r = string_creator
150
+ #r += span_div_string_creator
151
+ return r.join("\n")
152
+ end
153
+
154
+ end
155
+
156
+ #
157
+ # Description:
158
+ # Class for Pre element.
159
+ #
160
+ class Pre < NonControlElement
161
+ TAG = 'PRE'
162
+ def self.tag; TAG; end
163
+ end
164
+
165
+ #
166
+ # Description:
167
+ # Class for P element.
168
+ #
169
+ class P < NonControlElement
170
+ TAG = 'P'
171
+ def self.tag; TAG; end
172
+ end
173
+
174
+ #
175
+ # Description:
176
+ # Class for Div element.
177
+ #
178
+ class Div < NonControlElement
179
+ TAG = 'DIV'
180
+ def self.tag; TAG; end
181
+ end
182
+
183
+ #
184
+ # Description:
185
+ # Class for Span element.
186
+ #
187
+ class Span < NonControlElement
188
+ TAG = 'SPAN'
189
+ def self.tag; TAG; end
190
+ end
191
+
192
+ #
193
+ # Description:
194
+ # Class for Label element.
195
+ #
196
+ class Label < NonControlElement
197
+ TAG = 'LABEL'
198
+
199
+ #
200
+ # Description:
201
+ # Used to populate the properties in the to_s method.
202
+ #
203
+ #def label_string_creator
204
+ # n = []
205
+ # n << "for:".ljust(TO_S_SIZE) + self.for
206
+ # n << "inner text:".ljust(TO_S_SIZE) + self.text
207
+ # return n
208
+ #end
209
+ #private :label_string_creator
210
+
211
+ #
212
+ # Description:
213
+ # Creates string of properties of the object.
214
+ #
215
+ def to_s
216
+ assert_exists
217
+ super({"for" => "htmlFor","text" => "innerHTML"})
218
+ # r=r + label_string_creator
219
+ end
220
+ end
221
+
222
+ #
223
+ # Description:
224
+ # Class for table element.
225
+ #
226
+ class Table < Element
227
+ attr_accessor :element_name
228
+
229
+ #
230
+ # Description:
231
+ # Initializes the instance of table object.
232
+ #
233
+ # Input:
234
+ # - how - Attribute to identify the table element.
235
+ # - what - Value of that attribute.
236
+ #
237
+ def initialize(container, how, what)
238
+ @how = how
239
+ @what = what
240
+ @container = container
241
+ @o = nil
242
+ #super nil
243
+ end
244
+
245
+ #
246
+ # Description:
247
+ # Locate the table element.
248
+ #
249
+ def locate
250
+ if @how == :jssh_name
251
+ @element_name = @what
252
+ elsif @how == :xpath
253
+ @element_name = element_by_xpath(@container, @what)
254
+ else
255
+ @element_name = locate_tagged_element('TABLE', @how, @what)
256
+ end
257
+ @o = self
258
+ end
259
+
260
+ #
261
+ # Description:
262
+ # Override the highlight method, as if the tables rows are set to have a background color,
263
+ # this will override the table background color, and the normal flash method wont work
264
+ #
265
+ def highlight(set_or_clear )
266
+
267
+ if set_or_clear == :set
268
+ begin
269
+ @original_border = @o.border.to_i
270
+ if @o.border.to_i==1
271
+ @o.border = 2
272
+ else
273
+ @o.border=1
274
+ end
275
+ rescue
276
+ @original_border = nil
277
+ end
278
+ else
279
+ begin
280
+ @o.border= @original_border unless @original_border == nil
281
+ @original_border = nil
282
+ rescue
283
+ # we could be here for a number of reasons...
284
+ ensure
285
+ @original_border = nil
286
+ end
287
+ end
288
+ super
289
+ end
290
+
291
+ #
292
+ # Description:
293
+ # Used to populate the properties in the to_s method.
294
+ #
295
+ #def table_string_creator
296
+ # n = []
297
+ # n << "rows:".ljust(TO_S_SIZE) + self.row_count.to_s
298
+ # n << "cols:".ljust(TO_S_SIZE) + self.column_count.to_s
299
+ # return n
300
+ #end
301
+ #private :table_string_creator
302
+
303
+ # returns the properties of the object in a string
304
+ # raises an ObjectNotFound exception if the object cannot be found
305
+ # TODO: Implement to_s method for this class.
306
+
307
+ def to_s
308
+ assert_exists
309
+ r = super({"rows" => "rows.length","columns" => "columnLength", "cellspacing" => "cellspacing", "cellpadding" => "cellpadding", "border" => "border"})
310
+ # r += self.column_count.to_s
311
+ end
312
+
313
+ #
314
+ # Description:
315
+ # Gets the number of rows in the table.
316
+ #
317
+ # Output:
318
+ # Number of rows.
319
+ #
320
+ def row_count
321
+ assert_exists
322
+ return rows.length
323
+ end
324
+
325
+ #
326
+ # Description:
327
+ # Gets the table as a 2 dimensional array. Dont expect too much if there are nested tables, colspan etc.
328
+ #
329
+ # Output:
330
+ # 2D array with rows and column text of the table.
331
+ #
332
+ def to_a
333
+ assert_exists
334
+ y = []
335
+ table_rows = rows
336
+ for row in table_rows
337
+ x = []
338
+ row.each do |td|
339
+ x << td.to_s.strip
340
+ end
341
+ y << x
342
+ end
343
+ return y
344
+ end
345
+
346
+ #
347
+ # Description:
348
+ # Gets the array of rows in the table.
349
+ #
350
+ # Output:
351
+ # Array of rows.
352
+ #
353
+ def rows
354
+ assert_exists
355
+ arr_rows = get_rows
356
+ table_rows = Array.new(arr_rows.length)
357
+ for i in 0..arr_rows.length - 1 do
358
+ table_rows[i] = TableRow.new(@container, :jssh_name, arr_rows[i])
359
+ end
360
+ return table_rows
361
+ end
362
+
363
+ #
364
+ # Description:
365
+ # Get row at particular index in table.
366
+ #
367
+ # Input:
368
+ # key - row index
369
+ #
370
+ # Output:
371
+ # Table Row element
372
+ #
373
+ def [](key)
374
+ assert_exists
375
+ arr_rows = rows
376
+ return arr_rows[key - 1]
377
+ end
378
+
379
+ #
380
+ # Desription:
381
+ # Iterate over each table row element.
382
+ #
383
+ def each
384
+ assert_exists
385
+ arr_rows = rows
386
+ for i in 0..arr_rows.length - 1 do
387
+ yield arr_rows[i]
388
+ end
389
+ end
390
+
391
+ #
392
+ # Description:
393
+ # Get column count of first row in the table.
394
+ #
395
+ # Output:
396
+ # Number of columns in first row.
397
+ #
398
+ def column_count
399
+ assert_exists
400
+ arr_rows = rows
401
+ return arr_rows[0].column_count
402
+ end
403
+
404
+ #
405
+ # Description:
406
+ # Get values of specified column in each row.
407
+ #
408
+ # Input:
409
+ # Column number
410
+ #
411
+ # Output:
412
+ # Values of column (specified as input) in each row
413
+ #
414
+ def column_values(column)
415
+ assert_exists
416
+ arr_rows = rows
417
+ values = Array.new(arr_rows.length)
418
+ for i in 0..arr_rows.length - 1 do
419
+ values[i] = arr_rows[i][column].to_s
420
+ end
421
+ return values
422
+ end
423
+
424
+ #
425
+ # Description:
426
+ # Get values of all the column in specified row.
427
+ #
428
+ # Input:
429
+ # Row number.
430
+ #
431
+ # Output:
432
+ # Value of all columns present in the row.
433
+ #
434
+ def row_values(row)
435
+ assert_exists
436
+ arr_rows = rows
437
+ cells = arr_rows[row - 1].cells
438
+ values = Array.new(cells.length)
439
+ for i in 0..cells.length - 1 do
440
+ values[i] = cells[i].to_s
441
+ end
442
+ return values
443
+ end
444
+ end
445
+
446
+ # this class is a collection of the table body objects that exist in the table
447
+ # it wouldnt normally be created by a user, but gets returned by the bodies method of the Table object
448
+ # many of the methods available to this object are inherited from the Element class
449
+ # TODO: Implement TableBodies class.
450
+ #class TableBodies < Element
451
+ #
452
+ # Description:
453
+ # Initializes the form element.
454
+ #
455
+ # Input:
456
+ # - how - Attribute to identify the form element.
457
+ # - what - Value of that attribute.
458
+ #
459
+ #def initialize( parent_table)
460
+ # element = container
461
+ # @o = parent_table # in this case, @o is the parent table
462
+ #end
463
+
464
+ # returns the number of TableBodies that exist in the table
465
+ #def length
466
+ # assert_exists
467
+ # return @o.tBodies.length
468
+ #end
469
+
470
+ # returns the n'th Body as a FireWatir TableBody object
471
+ #def []n
472
+ # assert_exists
473
+ # return TableBody.new(element, :direct, ole_table_body_at_index(n))
474
+ #end
475
+
476
+ # returns an ole table body
477
+ #def ole_table_body_at_index(n)
478
+ # return @o.tBodies[(n-1).to_s]
479
+ #end
480
+
481
+ # iterates through each of the TableBodies in the Table. Yields a TableBody object
482
+ #def each
483
+ # 1.upto( @o.tBodies.length ) { |i| yield TableBody.new(element, :direct, ole_table_body_at_index(i)) }
484
+ #end
485
+
486
+ #end
487
+
488
+ # this class is a table body
489
+ # TODO: Implement TableBody class
490
+ #class TableBody < Element
491
+ #def locate
492
+ # @o = nil
493
+ # if @how == :direct
494
+ # @o = @what # in this case, @o is the table body
495
+ # elsif @how == :index
496
+ # @o = @parent_table.bodies.ole_table_body_at_index(@what)
497
+ # end
498
+ # @rows = []
499
+ # if @o
500
+ # @o.rows.each do |oo|
501
+ # @rows << TableRow.new(element, :direct, oo)
502
+ # end
503
+ # end
504
+ #end
505
+
506
+ #
507
+ # Description:
508
+ # Initializes the form element.
509
+ #
510
+ # Input:
511
+ # - how - Attribute to identify the form element.
512
+ # - what - Value of that attribute.
513
+ #
514
+ #def initialize( how, what, parent_table = nil)
515
+ # element = container
516
+ # @how = how
517
+ # @what = what
518
+ # @parent_table = parent_table
519
+ # super nil
520
+ #end
521
+
522
+ # returns the specified row as a TableRow object
523
+ #def [](n)
524
+ # assert_exists
525
+ # return @rows[n - 1]
526
+ #end
527
+
528
+ # iterates through all the rows in the table body
529
+ #def each
530
+ # locate
531
+ # 0.upto(@rows.length - 1) { |i| yield @rows[i] }
532
+ #end
533
+
534
+ # returns the number of rows in this table body.
535
+ #def length
536
+ # return @rows.length
537
+ #end
538
+ #end
539
+
540
+
541
+ #
542
+ # Description:
543
+ # Class for Table row element.
544
+ #
545
+ class TableRow < Element
546
+ attr_accessor :element_name
547
+
548
+ #
549
+ # Description:
550
+ # Locate the table row element on the page.
551
+ #
552
+ def locate
553
+ @o = nil
554
+ if @how == :jssh_name
555
+ @element_name = @what
556
+ elsif @how == :xpath
557
+ @element_name = element_by_xpath(@container, @what)
558
+ else
559
+ @element_name = locate_tagged_element("TR", @how, @what)
560
+ end
561
+ @o = self
562
+ end
563
+
564
+ #
565
+ # Description:
566
+ # Initializes the instance of table row object.
567
+ #
568
+ # Input:
569
+ # - how - Attribute to identify the table row element.
570
+ # - what - Value of that attribute.
571
+ #
572
+ def initialize(container, how, what)
573
+ @how = how
574
+ @what = what
575
+ @container = container
576
+ #super nil
577
+ end
578
+
579
+ #
580
+ # Description:
581
+ # Gets the length of columns in table row.
582
+ #
583
+ # Output:
584
+ # Length of columns in table row.
585
+ #
586
+ def column_count
587
+ assert_exists
588
+ arr_cells = cells
589
+ return arr_cells.length
590
+ end
591
+
592
+ #
593
+ # Description:
594
+ # Get cell at specified index in a row.
595
+ #
596
+ # Input:
597
+ # key - column index.
598
+ #
599
+ # Output:
600
+ # Table cell element at specified index.
601
+ #
602
+ def [] (key)
603
+ assert_exists
604
+ arr_cells = cells
605
+ return arr_cells[key - 1]
606
+ end
607
+
608
+ #
609
+ # Description:
610
+ # Iterate over each cell in a row.
611
+ #
612
+ def each
613
+ assert_exists
614
+ arr_cells = cells
615
+ for i in 0..arr_cells.length - 1 do
616
+ yield arr_cells[i]
617
+ end
618
+ end
619
+
620
+ #
621
+ # Description:
622
+ # Get array of all cells in Table Row
623
+ #
624
+ # Output:
625
+ # Array containing Table Cell elements.
626
+ #
627
+ def cells
628
+ assert_exists
629
+ arr_cells = get_cells
630
+ row_cells = Array.new(arr_cells.length)
631
+ for i in 0..arr_cells.length - 1 do
632
+ row_cells[i] = TableCell.new(@container, :jssh_name, arr_cells[i])
633
+ end
634
+ return row_cells
635
+ end
636
+ end
637
+
638
+ #
639
+ # Description:
640
+ # Class for Table Cell.
641
+ #
642
+ class TableCell < Element
643
+ attr_accessor :element_name
644
+
645
+ # Description:
646
+ # Locate the table cell element on the page.
647
+ #
648
+ def locate
649
+ if @how == :jssh_name
650
+ @element_name = @what
651
+ elsif @how == :xpath
652
+ @element_name = element_by_xpath(@container, @what)
653
+ else
654
+ @element_name = locate_tagged_element("TD", @how, @what)
655
+ end
656
+ @o = self
657
+ end
658
+
659
+ #
660
+ # Description:
661
+ # Initializes the instance of table cell object.
662
+ #
663
+ # Input:
664
+ # - how - Attribute to identify the table cell element.
665
+ # - what - Value of that attribute.
666
+ #
667
+ def initialize(container, how, what)
668
+ @how = how
669
+ @what = what
670
+ @container = container
671
+ #super nil
672
+ end
673
+
674
+ alias to_s text
675
+
676
+ #
677
+ # Description:
678
+ # Gets the col span of table cell.
679
+ #
680
+ # Output:
681
+ # Colspan of table cell.
682
+ #
683
+ def colspan
684
+ assert_exists
685
+ @o.colSpan
686
+ end
687
+
688
+ end
689
+
690
+ #
691
+ # Description:
692
+ # Class for Image element.
693
+ #
694
+ class Image < Element
695
+ attr_accessor :element_name
696
+ #
697
+ # Description:
698
+ # Initializes the instance of image object.
699
+ #
700
+ # Input:
701
+ # - how - Attribute to identify the image element.
702
+ # - what - Value of that attribute.
703
+ #
704
+ def initialize(container, how, what)
705
+ @how = how
706
+ @what = what
707
+ @container = container
708
+ end
709
+
710
+ # Description:
711
+ # Locate the image element on the page.
712
+ #
713
+ def locate
714
+ if @how == :jssh_name
715
+ @element_name = @what
716
+ elsif @how == :xpath
717
+ @element_name = element_by_xpath(@container, @what)
718
+ else
719
+ @element_name = locate_tagged_element('IMG', @how, @what)
720
+ end
721
+ @o = self
722
+ end
723
+
724
+ #
725
+ # Description:
726
+ # Used to populate the properties in to_s method. Not used anymore
727
+ #
728
+ def image_string_creator
729
+ n = []
730
+ n << "src:".ljust(TO_S_SIZE) + self.src.to_s
731
+ n << "file date:".ljust(TO_S_SIZE) + self.fileCreatedDate.to_s
732
+ n << "file size:".ljust(TO_S_SIZE) + self.fileSize.to_s
733
+ n << "width:".ljust(TO_S_SIZE) + self.width.to_s
734
+ n << "height:".ljust(TO_S_SIZE) + self.height.to_s
735
+ n << "alt:".ljust(TO_S_SIZE) + self.alt.to_s
736
+ return n
737
+ end
738
+ private :image_string_creator
739
+
740
+ # returns a string representation of the object
741
+ def to_s
742
+ assert_exists
743
+ super({"src" => "src","width" => "width","height" => "height","alt" => "alt"})
744
+ end
745
+
746
+ # this method returns the file created date of the image
747
+ #def fileCreatedDate
748
+ # assert_exists
749
+ # return @o.invoke("fileCreatedDate")
750
+ #end
751
+
752
+ # this method returns the filesize of the image
753
+ #def fileSize
754
+ # assert_exists
755
+ # return @o.invoke("fileSize").to_s
756
+ #end
757
+
758
+ #
759
+ # Description:
760
+ # Gets the width of the image in pixels, as a string.
761
+ #
762
+ # Output:
763
+ # Width of image (in pixels).
764
+ #
765
+ def width
766
+ assert_exists
767
+ return @o.invoke("width").to_s
768
+ end
769
+
770
+ #
771
+ # Description:
772
+ # Gets the height of the image in pixels, as a string.
773
+ #
774
+ # Output:
775
+ # Height of image (in pixels).
776
+ #
777
+ def height
778
+ assert_exists
779
+ return @o.invoke("height").to_s
780
+ end
781
+
782
+ # This method attempts to find out if the image was actually loaded by the web browser.
783
+ # If the image was not loaded, the browser is unable to determine some of the properties.
784
+ # We look for these missing properties to see if the image is really there or not.
785
+ # If the Disk cache is full ( tools menu -> Internet options -> Temporary Internet Files) , it may produce incorrect responses.
786
+ #def hasLoaded?
787
+ # locate
788
+ # raise UnknownObjectException, "Unable to locate image using #{@how} and #{@what}" if @o == nil
789
+ # return false if @o.fileCreatedDate == "" and @o.fileSize.to_i == -1
790
+ # return true
791
+ #end
792
+
793
+ #
794
+ # Description:
795
+ # Highlights the image ( in fact it adds or removes a border around the image)
796
+ #
797
+ # Input:
798
+ # - set_or_clear - :set to set the border, :clear to remove it
799
+ #
800
+ def highlight( set_or_clear )
801
+ if set_or_clear == :set
802
+ begin
803
+ @original_border = @o.border
804
+ @o.border = 1
805
+ rescue
806
+ @original_border = nil
807
+ end
808
+ else
809
+ begin
810
+ @o.border = @original_border
811
+ @original_border = nil
812
+ rescue
813
+ # we could be here for a number of reasons...
814
+ ensure
815
+ @original_border = nil
816
+ end
817
+ end
818
+ end
819
+ private :highlight
820
+ end
821
+
822
+
823
+ #
824
+ # Description:
825
+ # Class for Link element.
826
+ #
827
+ class Link < Element
828
+ attr_accessor :element_name
829
+ #
830
+ # Description:
831
+ # Initializes the instance of link element.
832
+ #
833
+ # Input:
834
+ # - how - Attribute to identify the link element.
835
+ # - what - Value of that attribute.
836
+ #
837
+ def initialize(container, how, what)
838
+ @how = how
839
+ @what = what
840
+ @container = container
841
+ end
842
+
843
+ #
844
+ # Description:
845
+ # Locate the link element on the page.
846
+ #
847
+ def locate
848
+ if @how == :jssh_name
849
+ @element_name = @what
850
+ elsif @how == :xpath
851
+ @element_name = element_by_xpath(@container, @what)
852
+ else
853
+ @element_name = locate_tagged_element('A', @how, @what)
854
+ end
855
+ @o = self
856
+ end
857
+
858
+ #TODO: if an image is used as part of the link, this will return true
859
+ #def link_has_image
860
+ # assert_exists
861
+ # return true if @o.getElementsByTagName("IMG").length > 0
862
+ # return false
863
+ #end
864
+
865
+ #TODO: this method returns the src of an image, if an image is used as part of the link
866
+ #def src # BUG?
867
+ # assert_exists
868
+ # if @o.getElementsByTagName("IMG").length > 0
869
+ # return @o.getElementsByTagName("IMG")[0.to_s].src
870
+ # else
871
+ # return ""
872
+ # end
873
+ #end
874
+
875
+ #
876
+ # Description:
877
+ # Used to populate the properties in to_s method.
878
+ #
879
+ #def link_string_creator
880
+ # n = []
881
+ # n << "href:".ljust(TO_S_SIZE) + self.href
882
+ # n << "inner text:".ljust(TO_S_SIZE) + self.text
883
+ # n << "img src:".ljust(TO_S_SIZE) + self.src if self.link_has_image
884
+ # return n
885
+ # end
886
+
887
+ # returns a textual description of the link
888
+
889
+ def to_s
890
+ assert_exists
891
+ super({"href" => "href","inner text" => "text"})
892
+ end
893
+ end
894
+
895
+ #
896
+ # Description:
897
+ # Base class containing items that are common between select list, text field, button, hidden, file field classes.
898
+ #
899
+ class InputElement < Element
900
+ attr_accessor :element_name
901
+ #
902
+ # Description:
903
+ # Locate the element on the page. Element can be a select list, text field, button, hidden, file field.
904
+ #
905
+ def locate
906
+ if @how == :jssh_name
907
+ @element_name = @what
908
+ elsif @how == :xpath
909
+ @element_name = element_by_xpath(@container, @what)
910
+ else
911
+ if(self.class::INPUT_TYPES.include?("select-one"))
912
+ @element_name = locate_tagged_element("select", @how, @what, self.class::INPUT_TYPES)
913
+ else
914
+ @element_name = locate_tagged_element("input", @how, @what, self.class::INPUT_TYPES)
915
+ end
916
+ end
917
+ @o = self
918
+ end
919
+ #
920
+ # Description:
921
+ # Initializes the instance of element.
922
+ #
923
+ # Input:
924
+ # - how - Attribute to identify the element.
925
+ # - what - Value of that attribute.
926
+ #
927
+ def initialize(container, how, what)
928
+ @how = how
929
+ @what = what
930
+ @container = container
931
+ @element_name = ""
932
+ #super(nil)
933
+ end
934
+ end
935
+
936
+ #
937
+ # Description:
938
+ # Class for SelectList element.
939
+ #
940
+ class SelectList < InputElement
941
+ INPUT_TYPES = ["select-one", "select-multiple"]
942
+
943
+ attr_accessor :o
944
+
945
+ #
946
+ # Description:
947
+ # Clears the selected items in the select box.
948
+ #
949
+ def clearSelection
950
+ assert_exists
951
+ #highlight( :set)
952
+ wait = false
953
+ @o.each do |selectBoxItem|
954
+ if selectBoxItem.selected
955
+ selectBoxItem.selected = false
956
+ wait = true
957
+ end
958
+ end
959
+ @o.wait if wait
960
+ #highlight( :clear)
961
+ end
962
+
963
+ def each
964
+ assert_exists
965
+ arr_options = options
966
+ #puts arr_options[0]#.length
967
+ for i in 0..arr_options.length - 1 do
968
+ yield Option.new(self, :jssh_name, arr_options[i])
969
+ end
970
+ end
971
+
972
+ #
973
+ # Description:
974
+ # Get option element at specified index in select list.
975
+ #
976
+ # Input:
977
+ # key - option index
978
+ #
979
+ # Output:
980
+ # Option element at specified index
981
+ #
982
+ def [] (key)
983
+ assert_exists
984
+ arr_options = options
985
+ return Option.new(self, :jssh_name, arr_options[key - 1])
986
+ end
987
+
988
+ #
989
+ # Description:
990
+ # Selects an item by text. If you need to select multiple items you need to call this function for each item.
991
+ #
992
+ # Input:
993
+ # - item - Text of item to be selected.
994
+ #
995
+ def select( item )
996
+ select_item_in_select_list(:text, item)
997
+ end
998
+
999
+ #
1000
+ # Description:
1001
+ # Selects an item by value. If you need to select multiple items you need to call this function for each item.
1002
+ #
1003
+ # Input:
1004
+ # - item - Value of the item to be selected.
1005
+ #
1006
+ def select_value( item )
1007
+ select_item_in_select_list( :value , item )
1008
+ end
1009
+
1010
+ # Description:
1011
+ # Selects item from the select box.
1012
+ #
1013
+ # Input:
1014
+ # - name - :value or :text - how we find an item in the select box
1015
+ # - item - value of either item text or item value.
1016
+ #
1017
+ def select_item_in_select_list(attribute, value)
1018
+ assert_exists
1019
+ highlight( :set )
1020
+ doBreak = false
1021
+ #element.log "Setting box #{@o.name} to #{attribute} #{value} "
1022
+ @o.each do |option| # items in the list
1023
+ if value.matches( option.invoke(attribute.to_s))
1024
+ if option.selected
1025
+ doBreak = true
1026
+ break
1027
+ else
1028
+ option.selected = true
1029
+ @o.fireEvent("onChange")
1030
+ @o.wait
1031
+ doBreak = true
1032
+ break
1033
+ end
1034
+ end
1035
+ end
1036
+ unless doBreak
1037
+ raise NoValueFoundException,
1038
+ "No option with #{attribute.to_s} of #{value} in this select element"
1039
+ end
1040
+ highlight( :clear )
1041
+ end
1042
+ private :select_item_in_select_list
1043
+
1044
+ #
1045
+ # Description:
1046
+ # Gets all the items in the select list as an array.
1047
+ # An empty array is returned if the select box has no contents.
1048
+ #
1049
+ # Output:
1050
+ # Array containing the items of the select list.
1051
+ #
1052
+ def getAllContents() # BUG: camel_case.rb
1053
+ assert_exists
1054
+ #element.log "There are #{@o.length} items"
1055
+ returnArray = []
1056
+ @o.each { |thisItem| returnArray << thisItem.text }
1057
+ return returnArray
1058
+ end
1059
+
1060
+ #
1061
+ # Description:
1062
+ # Gets all the selected items in the select list as an array.
1063
+ # An empty array is returned if the select box has no selected item.
1064
+ #
1065
+ # Output:
1066
+ # Array containing the selected items of the select list.
1067
+ #
1068
+ def getSelectedItems
1069
+ assert_exists
1070
+ returnArray = []
1071
+ #element.log "There are #{@o.length} items"
1072
+ @o.each do |thisItem|
1073
+ #puts "#{thisItem.selected}"
1074
+ if thisItem.selected
1075
+ #element.log "Item ( #{thisItem.text} ) is selected"
1076
+ returnArray << thisItem.text
1077
+ end
1078
+ end
1079
+ return returnArray
1080
+ end
1081
+
1082
+ #
1083
+ # Description:
1084
+ # Get the option using attribute and its value.
1085
+ #
1086
+ # Input:
1087
+ # - attribute - Attribute used to find the option.
1088
+ # - value - value of that attribute.
1089
+ #
1090
+ def option (attribute, value)
1091
+ assert_exists
1092
+ Option.new(self, attribute, value)
1093
+ end
1094
+ end
1095
+
1096
+ #
1097
+ # Description:
1098
+ # Class for Option element.
1099
+ #
1100
+ class Option < SelectList
1101
+ #
1102
+ # Description:
1103
+ # Initializes the instance of option object.
1104
+ #
1105
+ # Input:
1106
+ # - select_list - instance of select list element.
1107
+ # - attribute - Attribute to identify the option.
1108
+ # - value - Value of that attribute.
1109
+ #
1110
+ def initialize (select_list, attribute, value)
1111
+ @select_list = select_list
1112
+ @how = attribute
1113
+ @what = value
1114
+ @option = nil
1115
+ @element_name = ""
1116
+
1117
+ unless [:text, :value, :jssh_name].include? attribute
1118
+ raise MissingWayOfFindingObjectException,
1119
+ "Option does not support attribute #{@how}"
1120
+ end
1121
+ #puts @select_list.o.length
1122
+ #puts "what is : #{@what}, how is #{@how}, list name is : #{@select_list.element_name}"
1123
+ if(attribute == :jssh_name)
1124
+ @element_name = @what
1125
+ @option = self
1126
+ else
1127
+ @select_list.o.each do |option| # items in the list
1128
+ #puts "option is : #{option}"
1129
+ if(attribute == :value)
1130
+ match_value = option.value
1131
+ else
1132
+ match_value = option.text
1133
+ end
1134
+ #puts "value is #{match_value}"
1135
+ if value.matches( match_value) #option.invoke(attribute))
1136
+ @option = option
1137
+ @element_name = option.element_name
1138
+ break
1139
+ end
1140
+ end
1141
+ end
1142
+ end
1143
+
1144
+ #
1145
+ # Description:
1146
+ # Checks if option exists or not.
1147
+ #
1148
+ def assert_exists
1149
+ unless @option
1150
+ raise UnknownObjectException,
1151
+ "Unable to locate an option using #{@how} and #{@what}"
1152
+ end
1153
+ end
1154
+ private :assert_exists
1155
+
1156
+ #
1157
+ # Description:
1158
+ # Selects the option.
1159
+ #
1160
+ def select
1161
+ assert_exists
1162
+ if(@how == :text)
1163
+ @select_list.select(@what)
1164
+ elsif(@how == :value)
1165
+ @select_list.select_value(@what)
1166
+ end
1167
+ end
1168
+
1169
+ #
1170
+ # Description:
1171
+ # Gets the class name of the option.
1172
+ #
1173
+ # Output:
1174
+ # Class name of the option.
1175
+ #
1176
+ def class_name
1177
+ assert_exists
1178
+ option_class_name
1179
+ end
1180
+
1181
+ #
1182
+ # Description:
1183
+ # Gets the text of the option.
1184
+ #
1185
+ # Output:
1186
+ # Text of the option.
1187
+ #
1188
+ def text
1189
+ assert_exists
1190
+ option_text
1191
+ end
1192
+
1193
+ #
1194
+ # Description:
1195
+ # Gets the value of the option.
1196
+ #
1197
+ # Output:
1198
+ # Value of the option.
1199
+ #
1200
+ def value
1201
+ assert_exists
1202
+ option_value
1203
+ end
1204
+
1205
+ #
1206
+ # Description:
1207
+ # Gets the status of the option; whether it is selected or not.
1208
+ #
1209
+ # Output:
1210
+ # True if option is selected, false otherwise.
1211
+ #
1212
+ def selected
1213
+ assert_exists
1214
+ #@option.selected
1215
+ option_selected
1216
+ end
1217
+ end
1218
+
1219
+ #
1220
+ # Description:
1221
+ # Class for Button element.
1222
+ #
1223
+ class Button < InputElement
1224
+ INPUT_TYPES = ["button", "submit", "image", "reset"]
1225
+ end
1226
+
1227
+ #
1228
+ # Description:
1229
+ # Class for Text Field element.
1230
+ #
1231
+ class TextField < InputElement
1232
+ INPUT_TYPES = ["text", "password", "textarea"]
1233
+
1234
+ # Gets the size of the text field element.
1235
+ def_wrap :size
1236
+ # Gets max length of the text field element.
1237
+ def_wrap :maxlength
1238
+ # Returns true if the text field is read only, false otherwise.
1239
+ def_wrap :readonly?, :readOnly
1240
+
1241
+ #
1242
+ # Description:
1243
+ # Used to populate the properties in to_s method
1244
+ #
1245
+ #def text_string_creator
1246
+ # n = []
1247
+ # n << "length:".ljust(TO_S_SIZE) + self.size.to_s
1248
+ # n << "max length:".ljust(TO_S_SIZE) + self.maxlength.to_s
1249
+ # n << "read only:".ljust(TO_S_SIZE) + self.readonly?.to_s
1250
+ #
1251
+ # return n
1252
+ #end
1253
+ #private :text_string_creator
1254
+
1255
+ # TODO: Impelement the to_s method.
1256
+ def to_s
1257
+ assert_exists
1258
+ super({"length" => "size","max length" => "maxLength","read only" => "readOnly" })
1259
+ end
1260
+
1261
+ #
1262
+ # Description:
1263
+ # Checks if object is read-only or not.
1264
+ #
1265
+ def assert_not_readonly
1266
+ raise ObjectReadOnlyException, "Textfield #{@how} and #{@what} is read only." if self.readonly?
1267
+ end
1268
+
1269
+ #
1270
+ # Description:
1271
+ # Checks if the provided text matches with the contents of text field. Text can be a string or regular expression.
1272
+ #
1273
+ # Input:
1274
+ # - containsThis - Text to verify.
1275
+ #
1276
+ # Output:
1277
+ # True if provided text matches with the contents of text field, false otherwise.
1278
+ #
1279
+ def verify_contains( containsThis )
1280
+ assert_exists
1281
+ if containsThis.kind_of? String
1282
+ return true if self.value == containsThis
1283
+ elsif containsThis.kind_of? Regexp
1284
+ return true if self.value.match(containsThis) != nil
1285
+ end
1286
+ return false
1287
+ end
1288
+
1289
+ # this method is used to drag the entire contents of the text field to another text field
1290
+ # 19 Jan 2005 - It is added as prototype functionality, and may change
1291
+ # * destination_how - symbol, :id, :name how we identify the drop target
1292
+ # * destination_what - string or regular expression, the name, id, etc of the text field that will be the drop target
1293
+ # TODO: Can we have support for this in Firefox.
1294
+ #def dragContentsTo( destination_how , destination_what)
1295
+ # assert_exists
1296
+ # destination = element.text_field(destination_how, destination_what)
1297
+ # raise UnknownObjectException , "Unable to locate destination using #{destination_how } and #{destination_what } " if destination.exists? == false
1298
+
1299
+ # @o.focus
1300
+ # @o.select()
1301
+ # value = self.value
1302
+
1303
+ # @o.fireEvent("onSelect")
1304
+ # @o.fireEvent("ondragstart")
1305
+ # @o.fireEvent("ondrag")
1306
+ # destination.fireEvent("onDragEnter")
1307
+ # destination.fireEvent("onDragOver")
1308
+ # destination.fireEvent("ondrop")
1309
+
1310
+ # @o.fireEvent("ondragend")
1311
+ # destination.value= ( destination.value + value.to_s )
1312
+ # self.value = ""
1313
+ #end
1314
+
1315
+ #
1316
+ # Description:
1317
+ # Clears the contents of the text field.
1318
+ # Raises ObjectDisabledException if text field is disabled.
1319
+ # Raises ObjectReadOnlyException if text field is read only.
1320
+ #
1321
+ def clear
1322
+ assert_exists
1323
+ assert_enabled
1324
+ assert_not_readonly
1325
+
1326
+ highlight(:set)
1327
+
1328
+ @o.scrollIntoView
1329
+ @o.focus
1330
+ @o.select()
1331
+ @o.fireEvent("onSelect")
1332
+ @o.value = ""
1333
+ @o.fireEvent("onKeyPress")
1334
+ @o.fireEvent("onChange")
1335
+ @container.wait()
1336
+ highlight(:clear)
1337
+ end
1338
+
1339
+ #
1340
+ # Description:
1341
+ # Append the provided text to the contents of the text field.
1342
+ # Raises ObjectDisabledException if text field is disabled.
1343
+ # Raises ObjectReadOnlyException if text field is read only.
1344
+ #
1345
+ # Input:
1346
+ # - setThis - Text to be appended.
1347
+ #
1348
+ def append( setThis)
1349
+ assert_exists
1350
+ assert_enabled
1351
+ assert_not_readonly
1352
+
1353
+ highlight(:set)
1354
+ @o.scrollIntoView
1355
+ @o.focus
1356
+ doKeyPress( setThis )
1357
+ highlight(:clear)
1358
+ end
1359
+
1360
+ #
1361
+ # Description:
1362
+ # Sets the contents of the text field to the provided text. Overwrite the existing contents.
1363
+ # Raises ObjectDisabledException if text field is disabled.
1364
+ # Raises ObjectReadOnlyException if text field is read only.
1365
+ #
1366
+ # Input:
1367
+ # - setThis - Text to be set.
1368
+ #
1369
+ def set( setThis )
1370
+ assert_exists
1371
+ assert_enabled
1372
+ assert_not_readonly
1373
+
1374
+ highlight(:set)
1375
+ @o.scrollIntoView
1376
+ @o.focus
1377
+ @o.select()
1378
+ @o.fireEvent("onSelect")
1379
+ @o.value = ""
1380
+ @o.fireEvent("onKeyPress")
1381
+ doKeyPress( setThis )
1382
+ highlight(:clear)
1383
+ @o.fireEvent("onChange")
1384
+ @o.fireEvent("onBlur")
1385
+ end
1386
+
1387
+ #
1388
+ # Description:
1389
+ # Sets the text of the text field withoud firing the events like onKeyPress, onKeyDown etc. This should not be used generally, but it
1390
+ # is useful in situations where you need to set large text to the text field and you know that you don't have any event to be
1391
+ # fired.
1392
+ #
1393
+ # Input:
1394
+ # - v - Text to be set.
1395
+ #
1396
+ #def value=(v)
1397
+ # assert_exists
1398
+ # @o.value = v.to_s
1399
+ #end
1400
+
1401
+ #
1402
+ # Description:
1403
+ # Used to set the value of text box and fires the event onKeyPress, onKeyDown, onKeyUp after each character.
1404
+ # Shouldnot be used externally. Used internally by set and append methods.
1405
+ #
1406
+ # Input:
1407
+ # - value - The string to enter into the text field
1408
+ #
1409
+ def doKeyPress( value )
1410
+ begin
1411
+ maxLength = @o.maxLength
1412
+ if (maxLength != -1 && value.length > maxLength)
1413
+ original_value = value
1414
+ value = original_value[0..maxLength]
1415
+ element.log " Supplied string is #{suppliedValue.length} chars, which exceeds the max length (#{maxLength}) of the field. Using value: #{value}"
1416
+ end
1417
+ rescue
1418
+ # probably a text area - so it doesnt have a max Length
1419
+ maxLength = -1
1420
+ end
1421
+ for i in 0..value.length-1
1422
+ #sleep element.typingspeed # typing speed
1423
+ c = value[i,1]
1424
+ #element.log " adding c.chr " + c #.chr.to_s
1425
+ @o.value = "#{(@o.value.to_s + c)}" #c.chr
1426
+ @o.fireEvent("onKeyDown")
1427
+ @o.fireEvent("onKeyPress")
1428
+ @o.fireEvent("onKeyUp")
1429
+ end
1430
+
1431
+ end
1432
+ private :doKeyPress
1433
+
1434
+ alias readOnly? :readonly?
1435
+ alias getContents value
1436
+ alias maxLength maxlength
1437
+
1438
+ end
1439
+
1440
+ #
1441
+ # Description:
1442
+ # Class for Hidden Field element.
1443
+ #
1444
+ class Hidden < TextField
1445
+ INPUT_TYPES = ["hidden"]
1446
+
1447
+ #
1448
+ # Description:
1449
+ # Sets the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
1450
+ #
1451
+ # Input:
1452
+ # n - Value to be set.
1453
+ #
1454
+ def set(n)
1455
+ self.value=n
1456
+ end
1457
+
1458
+ #
1459
+ # Description:
1460
+ # Appends the value to the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
1461
+ #
1462
+ # Input:
1463
+ # n - Value to be appended.
1464
+ #
1465
+ def append(n)
1466
+ self.value = self.value.to_s + n.to_s
1467
+ end
1468
+
1469
+ #
1470
+ # Description:
1471
+ # Clears the value of the hidden field. Overriden in this class, as there is no way to set focus to a hidden field
1472
+ #
1473
+ def clear
1474
+ self.value = ""
1475
+ end
1476
+
1477
+ #
1478
+ # Description:
1479
+ # Does nothing, as you cant set focus to a hidden field. Overridden here so that exception doesn't occurs.
1480
+ #
1481
+ def focus
1482
+ end
1483
+
1484
+ end
1485
+
1486
+ #
1487
+ # Description:
1488
+ # Class for FileField element.
1489
+ #
1490
+ class FileField < InputElement
1491
+ INPUT_TYPES = ["file"]
1492
+
1493
+ #
1494
+ # Description:
1495
+ # Sets the path of the file in the textbox.
1496
+ #
1497
+ # Input:
1498
+ # setPath - Path of the file.
1499
+ #
1500
+ def set(setPath)
1501
+ assert_exists
1502
+
1503
+ setFileFieldValue(setPath)
1504
+ end
1505
+ end
1506
+
1507
+ #
1508
+ # Description:
1509
+ # Base class for checkbox and radio button elements.
1510
+ #
1511
+ class RadioCheckCommon < Element
1512
+ attr_accessor :element_name
1513
+ #
1514
+ # Description:
1515
+ # Locate the element on the page. Element can be a checkbox or radio button.
1516
+ #
1517
+ def locate
1518
+ if @how == :jssh_name
1519
+ @element_name = @what
1520
+ elsif @how == :xpath
1521
+ @element_name = element_by_xpath(@container, @what)
1522
+ else
1523
+ @element_name = locate_tagged_element("input", @how, @what, @type, @value)
1524
+ end
1525
+ @o = self
1526
+ end
1527
+
1528
+ #
1529
+ # Description:
1530
+ # Initializes the instance of element object. Element can be checkbox or radio button.
1531
+ #
1532
+ # Input:
1533
+ # - how - Attribute to identify the element.
1534
+ # - what - Value of that attribute.
1535
+ # - type - Type of element i.e. radio or checkbox
1536
+ # - value - value of the element.
1537
+ #
1538
+ def initialize(container, how, what, type, value = nil)
1539
+ @how = how
1540
+ @what = what
1541
+ @type = type
1542
+ @value = value
1543
+ @container = container
1544
+ end
1545
+
1546
+ #
1547
+ # Description:
1548
+ # Checks if element i.e. radio button or check box is checked or not.
1549
+ #
1550
+ # Output:
1551
+ # True if element is checked, false otherwise.
1552
+ #
1553
+ def isSet?
1554
+ assert_exists
1555
+ return @o.checked
1556
+ end
1557
+ alias getState isSet?
1558
+
1559
+ #
1560
+ # Description:
1561
+ # Unchecks the radio button or check box element.
1562
+ # Raises ObjectDisabledException exception if element is disabled.
1563
+ #
1564
+ def clear
1565
+ assert_exists
1566
+ assert_enabled
1567
+ #highlight(:set)
1568
+ set_clear_item(false)
1569
+ #highlight(:clear)
1570
+ end
1571
+
1572
+ #
1573
+ # Description:
1574
+ # Checks the radio button or check box element.
1575
+ # Raises ObjectDisabledException exception if element is disabled.
1576
+ #
1577
+ def set
1578
+ assert_exists
1579
+ assert_enabled
1580
+ #highlight(:set)
1581
+ set_clear_item(true)
1582
+ #highlight(:clear)
1583
+ end
1584
+
1585
+ #
1586
+ # Description:
1587
+ # Used by clear and set method to uncheck and check radio button and checkbox element respectively.
1588
+ #
1589
+ def set_clear_item(set)
1590
+ if set != @o.isSet?
1591
+ @o.fire_event("onclick")
1592
+ @container.wait
1593
+ end
1594
+ end
1595
+ private :set_clear_item
1596
+
1597
+ end
1598
+
1599
+ #
1600
+ # Description:
1601
+ # Class for RadioButton element.
1602
+ #
1603
+ class Radio < RadioCheckCommon
1604
+ def clear
1605
+ assert_exists
1606
+ assert_enabled
1607
+ #higlight(:set)
1608
+ @o.checked = false
1609
+ #highlight(:clear)
1610
+ end
1611
+ end
1612
+
1613
+ #
1614
+ # Description:
1615
+ # Class for Checkbox element.
1616
+ #
1617
+ class CheckBox < RadioCheckCommon
1618
+
1619
+ #
1620
+ # Description:
1621
+ # Checks or unchecks the checkbox. If no value is supplied it will check the checkbox.
1622
+ # Raises ObjectDisabledException exception if the object is disabled
1623
+ #
1624
+ # Input:
1625
+ # - set_or_clear - Parameter indicated whether to check or uncheck the checkbox.
1626
+ # True to check the check box, false for unchecking the checkbox.
1627
+ #
1628
+ def set( set_or_clear=true )
1629
+ assert_exists
1630
+ assert_enabled
1631
+ highlight(:set)
1632
+
1633
+ if set_or_clear == true
1634
+ if @o.checked == false
1635
+ set_clear_item( true )
1636
+ end
1637
+ else
1638
+ self.clear
1639
+ end
1640
+ highlight(:clear )
1641
+ end
1642
+
1643
+ #
1644
+ # Description:
1645
+ # Unchecks the checkbox.
1646
+ # Raises ObjectDisabledException exception if the object is disabled
1647
+ #
1648
+ def clear
1649
+ assert_exists
1650
+ assert_enabled
1651
+ highlight( :set)
1652
+ if @o.checked == true
1653
+ set_clear_item( false )
1654
+ end
1655
+ highlight( :clear)
1656
+ end
1657
+ end
1658
+
1659
+ # this class is the super class for the iterator classes ( buttons, links, spans etc
1660
+ # it would normally only be accessed by the iterator methods ( spans , links etc) of IE
1661
+
1662
+ #class ElementCollections
1663
+ # include Enumerable
1664
+ # include Container
1665
+ # Super class for all the iteractor classes
1666
+ # * container - an instance of an IE object
1667
+ # def initialize( container)
1668
+ # element = container
1669
+ # @length = length() # defined by subclasses
1670
+
1671
+ # set up the items we want to display when the show method s used
1672
+ # set_show_items
1673
+ # end
1674
+
1675
+ # private
1676
+ # def set_show_items
1677
+ # @show_attributes = AttributeLengthPairs.new( "id" , 20)
1678
+ # @show_attributes.add( "name" , 20)
1679
+ # end
1680
+
1681
+ # public
1682
+ # def get_length_of_input_objects(object_type)
1683
+ # object_types =
1684
+ # if object_type.kind_of? Array
1685
+ # object_type
1686
+ # else
1687
+ # [ object_type ]
1688
+ # end
1689
+
1690
+ # length = 0
1691
+ # objects = element.document.getElementsByTagName("INPUT")
1692
+ # if objects.length > 0
1693
+ # objects.each do |o|
1694
+ # length += 1 if object_types.include?(o.invoke("type").downcase )
1695
+ # end
1696
+ # end
1697
+ # return length
1698
+ # end
1699
+
1700
+ # iterate through each of the elements in the collection in turn
1701
+ # def each
1702
+ # 0.upto( @length-1 ) { |i | yield iterator_object(i) }
1703
+ # end
1704
+
1705
+ # allows access to a specific item in the collection
1706
+ # def [](n)
1707
+ # return iterator_object(n-1)
1708
+ # end
1709
+
1710
+ # this method is the way to show the objects, normally used from irb
1711
+ # def show
1712
+ # s="index".ljust(6)
1713
+ # @show_attributes.each do |attribute_length_pair|
1714
+ # s=s + attribute_length_pair.attribute.ljust(attribute_length_pair.length)
1715
+ # end
1716
+
1717
+ # index = 1
1718
+ # self.each do |o|
1719
+ # s= s+"\n"
1720
+ # s=s + index.to_s.ljust(6)
1721
+ # @show_attributes.each do |attribute_length_pair|
1722
+ # begin
1723
+ # s=s + eval( 'o.getOLEObject.invoke("#{attribute_length_pair.attribute}")').to_s.ljust( attribute_length_pair.length )
1724
+ # rescue=>e
1725
+ # s=s+ " ".ljust( attribute_length_pair.length )
1726
+ # end
1727
+ # end
1728
+ # index+=1
1729
+ # end
1730
+ # puts s
1731
+ # end
1732
+
1733
+ # this method creates an object of the correct type that the iterators use
1734
+ # private
1735
+ # def iterator_object(i)
1736
+ # element_class.new(element, :index, i+1)
1737
+ # end
1738
+ #end
1739
+
1740
+ #--
1741
+ # These classes are not for public consumption, so we switch off rdoc
1742
+
1743
+ # presumes element_class or element_tag is defined
1744
+ # for subclasses of ElementCollections
1745
+ # module CommonCollection
1746
+ # def element_tag
1747
+ # element_class.tag
1748
+ # end
1749
+ # def length
1750
+ # element.document.getElementsByTagName(element_tag).length
1751
+ # end
1752
+ # end
1753
+
1754
+ # This class is used as part of the .show method of the iterators class
1755
+ # it would not normally be used by a user
1756
+ #class AttributeLengthPairs
1757
+
1758
+ # This class is used as part of the .show method of the iterators class
1759
+ # it would not normally be used by a user
1760
+ # class AttributeLengthHolder
1761
+ # attr_accessor :attribute
1762
+ # attr_accessor :length
1763
+
1764
+ # def initialize( attrib, length)
1765
+ # @attribute = attrib
1766
+ # @length = length
1767
+ # end
1768
+ # end
1769
+
1770
+ # def initialize( attrib=nil , length=nil)
1771
+ # @attr=[]
1772
+ # add( attrib , length ) if attrib
1773
+ # @index_counter=0
1774
+ # end
1775
+
1776
+ # # BUG: Untested. (Null implementation passes all tests.)
1777
+ # def add( attrib , length)
1778
+ # @attr << AttributeLengthHolder.new( attrib , length )
1779
+ # end
1780
+
1781
+ # def delete(attrib)
1782
+ # item_to_delete=nil
1783
+ # @attr.each_with_index do |e,i|
1784
+ # item_to_delete = i if e.attribute==attrib
1785
+ # end
1786
+ # @attr.delete_at(item_to_delete ) unless item_to_delete == nil
1787
+ # end
1788
+
1789
+ # def next
1790
+ # temp = @attr[@index_counter]
1791
+ # @index_counter +=1
1792
+ # return temp
1793
+ # end
1794
+
1795
+ # def each
1796
+ # 0.upto( @attr.length-1 ) { |i | yield @attr[i] }
1797
+ # end
1798
+ #end
1799
+
1800
+ # resume rdoc
1801
+ #
1802
+
1803
+
1804
+ #
1805
+ # Description:
1806
+ # Class for accessing all the button elements in the document.
1807
+ # It would normally only be accessed by the FireWatir::Container#buttons method
1808
+ #
1809
+ class Buttons < ElementCollections
1810
+ #
1811
+ # Description:
1812
+ # Initializes the instance of Buttons class.
1813
+ #
1814
+ def initialize(container)
1815
+ @container = container
1816
+ elements = locate_tagged_elements("input", ["button", "image", "submit", "reset"])
1817
+ length = elements.length
1818
+ #puts "length is : #{length}"
1819
+ @element_objects = Array.new(length)
1820
+ for i in 0..length - 1 do
1821
+ @element_objects[i] = Button.new(container, :jssh_name, elements[i])
1822
+ end
1823
+ end
1824
+ #def element_class; Button; end
1825
+ #def length
1826
+ # get_length_of_input_objects(["button", "submit", "image"])
1827
+ #end
1828
+
1829
+ #private
1830
+ #def set_show_items
1831
+ # super
1832
+ # @show_attributes.add( "disabled" , 9)
1833
+ # @show_attributes.add( "value" , 20)
1834
+ #end
1835
+ end
1836
+
1837
+
1838
+ #
1839
+ # Description:
1840
+ # Class for accessing all the File Field elements in the document.
1841
+ # It would normally only be accessed by the FireWatir::Container#file_fields method
1842
+ #
1843
+ class FileFields< ElementCollections
1844
+ #
1845
+ # Description:
1846
+ # Initializes the instance of FileFields class.
1847
+ #
1848
+ def initialize(container)
1849
+ @container = container
1850
+ elements = locate_tagged_elements("input", ["file"])
1851
+ length = elements.length
1852
+ #puts "length is : #{length}"
1853
+ @element_objects = Array.new(length)
1854
+ for i in 0..length - 1 do
1855
+ @element_objects[i] = FileField.new(container, :jssh_name, elements[i])
1856
+ end
1857
+ end
1858
+ # def element_class; FileField; end
1859
+ # def length
1860
+ # get_length_of_input_objects(["file"])
1861
+ # end
1862
+
1863
+ # private
1864
+ # def set_show_items
1865
+ # super
1866
+ # @show_attributes.add( "disabled" , 9)
1867
+ # @show_attributes.add( "value" , 20)
1868
+ # end
1869
+ end
1870
+
1871
+
1872
+ #
1873
+ # Description:
1874
+ # Class for accessing all the CheckBox elements in the document.
1875
+ # It would normally only be accessed by the FireWatir::Container#checkboxes method
1876
+ #
1877
+ class CheckBoxes < ElementCollections
1878
+ #
1879
+ # Description:
1880
+ # Initializes the instance of CheckBoxes class.
1881
+ #
1882
+ def initialize(container)
1883
+ @container = container
1884
+ elements = locate_tagged_elements("input", ["checkbox"])
1885
+ length = elements.length
1886
+ #puts "length is : #{length}"
1887
+ @element_objects = Array.new(length)
1888
+ for i in 0..length - 1 do
1889
+ @element_objects[i] = CheckBox.new(container, :jssh_name, elements[i], ["checkbox"])
1890
+ end
1891
+ end
1892
+ # def element_class; CheckBox; end
1893
+ # def length
1894
+ # get_length_of_input_objects("checkbox")
1895
+ # end
1896
+ # # this method creates an object of the correct type that the iterators use
1897
+ # private
1898
+ # def iterator_object(i)
1899
+ # element.checkbox(:index, i+1)
1900
+ # end
1901
+ end
1902
+
1903
+ #
1904
+ # Description:
1905
+ # Class for accessing all the Radio button elements in the document.
1906
+ # It would normally only be accessed by the FireWatir::Container#radios method
1907
+ #
1908
+ class Radios < ElementCollections
1909
+ #
1910
+ # Description:
1911
+ # Initializes the instance of Radios class.
1912
+ #
1913
+ def initialize(container)
1914
+ @container = container
1915
+ elements = locate_tagged_elements("input", ["radio"])
1916
+ length = elements.length
1917
+ #puts "length is : #{length}"
1918
+ @element_objects = Array.new(length)
1919
+ for i in 0..length - 1 do
1920
+ @element_objects[i] = Radio.new(container, :jssh_name, elements[i], ["radio"])
1921
+ end
1922
+ end
1923
+ # def element_class; Radio; end
1924
+ # def length
1925
+ # get_length_of_input_objects("radio")
1926
+ # end
1927
+ # this method creates an object of the correct type that the iterators use
1928
+ # private
1929
+ # def iterator_object(i)
1930
+ # element.radio(:index, i+1)
1931
+ # end
1932
+ end
1933
+
1934
+ #
1935
+ # Description:
1936
+ # Class for accessing all the select list elements in the document.
1937
+ # It would normally only be accessed by the FireWatir::Container#select_lists method
1938
+ #
1939
+ class SelectLists < ElementCollections
1940
+ #
1941
+ # Description:
1942
+ # Initializes the instance of SelectLists class.
1943
+ #
1944
+ def initialize(container)
1945
+ #super(container, "select",["select-one","select-multiple"])
1946
+ @container = container
1947
+ elements = locate_tagged_elements("select", ["select-one", "select-multiple"])
1948
+ length = elements.length
1949
+ #puts "length is : #{length}"
1950
+ @element_objects = Array.new(length)
1951
+ for i in 0..length - 1 do
1952
+ @element_objects[i] = SelectList.new(container, :jssh_name, elements[i])
1953
+ end
1954
+ end
1955
+ # include CommonCollection
1956
+ # def element_class; SelectList; end
1957
+ # def element_tag; 'SELECT'; end
1958
+ end
1959
+
1960
+ #
1961
+ # Description:
1962
+ # Class for accessing all the link elements in the document.
1963
+ # It would normally only be accessed by the FireWatir::Container#links method
1964
+ #
1965
+ class Links < ElementCollections
1966
+ #
1967
+ # Description:
1968
+ # Initializes the instance of Links class.
1969
+ #
1970
+ def initialize(container)
1971
+ #super(container, "a")
1972
+ @container = container
1973
+ elements = locate_tagged_elements("a")
1974
+ length = elements.length
1975
+ #puts "length is : #{length}"
1976
+ @element_objects = Array.new(length)
1977
+ for i in 0..length - 1 do
1978
+ @element_objects[i] = Link.new(container, :jssh_name, elements[i])
1979
+ end
1980
+ end
1981
+ # include CommonCollection
1982
+ # def element_class; Link; end
1983
+ # def element_tag; 'A'; end
1984
+
1985
+ # private
1986
+ # def set_show_items
1987
+ # super
1988
+ # @show_attributes.add("href", 60)
1989
+ # @show_attributes.add("innerText" , 60)
1990
+ # end
1991
+
1992
+ end
1993
+
1994
+ #
1995
+ # Description:
1996
+ # Class for accessing all the image elements in the document.
1997
+ # It would normally only be accessed by the FireWatir::Container#images method
1998
+ #
1999
+ class Images < ElementCollections
2000
+ #
2001
+ # Description:
2002
+ # Initializes the instance of Images class.
2003
+ #
2004
+ def initialize(container)
2005
+ #super(container, "img")
2006
+ @container = container
2007
+ elements = locate_tagged_elements("img")
2008
+ length = elements.length
2009
+ #puts "length is : #{length}"
2010
+ @element_objects = Array.new(length)
2011
+ for i in 0..length - 1 do
2012
+ @element_objects[i] = Image.new(container, :jssh_name, elements[i])
2013
+ end
2014
+ end
2015
+ # def element_class; Image; end
2016
+ # def length
2017
+ # element.document.images.length
2018
+ # end
2019
+
2020
+ # private
2021
+ # def set_show_items
2022
+ # super
2023
+ # @show_attributes.add("src", 60)
2024
+ # @show_attributes.add("alt", 30)
2025
+ # end
2026
+
2027
+ end
2028
+
2029
+ #
2030
+ # Description:
2031
+ # Class for accessing all the text field elements in the document.
2032
+ # It would normally only be accessed by the FireWatir::Container#text_fields method
2033
+ #
2034
+ class TextFields < ElementCollections
2035
+ #
2036
+ # Description:
2037
+ # Initializes the instance of TextFields class.
2038
+ #
2039
+ def initialize(container)
2040
+ #super(container, "input",["text","textarea","password"])
2041
+ @container = container
2042
+ elements = locate_tagged_elements("input", ["text", "textarea", "password"])
2043
+ length = elements.length
2044
+ #puts "length is : #{length}"
2045
+ @element_objects = Array.new(length)
2046
+ for i in 0..length - 1 do
2047
+ @element_objects[i] = TextField.new(container, :jssh_name, elements[i])
2048
+ end
2049
+ end
2050
+ # def element_class; TextField; end
2051
+ # def length
2052
+ # # text areas are also included in the TextFields, but we need to get them seperately
2053
+ # get_length_of_input_objects( ["text" , "password"] ) +
2054
+ # element.document.getElementsByTagName("textarea").length
2055
+ # end
2056
+ end
2057
+
2058
+ #
2059
+ # Description:
2060
+ # Class for accessing all the hidden elements in the document.
2061
+ # It would normally only be accessed by the FireWatir::Container#hiddens method
2062
+ #
2063
+ class Hiddens < ElementCollections
2064
+ #
2065
+ # Description:
2066
+ # Initializes the instance of Hiddens class.
2067
+ #
2068
+ def initialize(container)
2069
+ #super(container, "input",["hidden"])
2070
+ @container = container
2071
+ elements = locate_tagged_elements("input", ["hidden"])
2072
+ length = elements.length
2073
+ #puts "length is : #{length}"
2074
+ @element_objects = Array.new(length)
2075
+ for i in 0..length - 1 do
2076
+ @element_objects[i] = Hidden.new(container, :jssh_name, elements[i])
2077
+ end
2078
+ end
2079
+ # def element_class; Hidden; end
2080
+ # def length
2081
+ # get_length_of_input_objects("hidden")
2082
+ # end
2083
+ end
2084
+
2085
+ #
2086
+ # Description:
2087
+ # Class for accessing all the table elements in the document.
2088
+ # It would normally only be accessed by the FireWatir::Container#tables method
2089
+ #
2090
+ class Tables < ElementCollections
2091
+ #
2092
+ # Description:
2093
+ # Initializes the instance of Tables class.
2094
+ #
2095
+ def initialize(container)
2096
+ #super(container, "table")
2097
+ @container = container
2098
+ elements = locate_tagged_elements("table")
2099
+ length = elements.length
2100
+ #puts "length is : #{length}"
2101
+ @element_objects = Array.new(length)
2102
+ for i in 0..length - 1 do
2103
+ @element_objects[i] = Table.new(container, :jssh_name, elements[i])
2104
+ end
2105
+ end
2106
+ # include CommonCollection
2107
+ # def element_class; Table; end
2108
+ # def element_tag; 'TABLE'; end
2109
+
2110
+ # private
2111
+ # def set_show_items
2112
+ # super
2113
+ # @show_attributes.delete( "name")
2114
+ # end
2115
+ end
2116
+
2117
+ #
2118
+ # Description:
2119
+ # Class for accessing all the label elements in the document.
2120
+ # It would normally only be accessed by the FireWatir::Container#labels method
2121
+ #
2122
+ class Labels < ElementCollections
2123
+ #
2124
+ # Description:
2125
+ # Initializes the instance of Labels class.
2126
+ #
2127
+ def initialize(container)
2128
+ #super(container, "label")
2129
+ @container = container
2130
+ elements = locate_tagged_elements("label")
2131
+ length = elements.length
2132
+ #puts "length is : #{length}"
2133
+ @element_objects = Array.new(length)
2134
+ for i in 0..length - 1 do
2135
+ @element_objects[i] = Label.new(container, :jssh_name, elements[i])
2136
+ end
2137
+ end
2138
+ # include CommonCollection
2139
+ # def element_class; Label; end
2140
+ # def element_tag; 'LABEL'; end
2141
+
2142
+ # private
2143
+ # def set_show_items
2144
+ # super
2145
+ # @show_attributes.add("htmlFor", 20)
2146
+ # end
2147
+ end
2148
+
2149
+ #
2150
+ # Description:
2151
+ # Class for accessing all the pre element in the document.
2152
+ # It would normally only be accessed by the FireWatir::Container#pres method
2153
+ #
2154
+ class Pres < ElementCollections
2155
+ #
2156
+ # Description:
2157
+ # Initializes the instance of Pres class.
2158
+ #
2159
+ def initialize(container)
2160
+ #super(container, "pre")
2161
+ @container = container
2162
+ elements = locate_tagged_elements("pre")
2163
+ length = elements.length
2164
+ #puts "length is : #{length}"
2165
+ @element_objects = Array.new(length)
2166
+ for i in 0..length - 1 do
2167
+ @element_objects[i] = Pre.new(container, :jssh_name, elements[i])
2168
+ end
2169
+ end
2170
+ # include CommonCollection
2171
+ # def element_class; Pre; end
2172
+
2173
+ # def set_show_items
2174
+ # super
2175
+ # @show_attributes.delete( "name" )
2176
+ # @show_attributes.add( "className", 20 )
2177
+ # end
2178
+ end
2179
+
2180
+ #
2181
+ # Description:
2182
+ # Class for accessing all the paragraph elements in the document.
2183
+ # It would normally only be accessed by the FireWatir::Container#ps method
2184
+ #
2185
+ class Ps < ElementCollections
2186
+ #
2187
+ # Description:
2188
+ # Initializes the instance of Ps class.
2189
+ #
2190
+ def initialize(container)
2191
+ #super(container, "p")
2192
+ @container = container
2193
+ elements = locate_tagged_elements("p")
2194
+ length = elements.length
2195
+ #puts "length is : #{length}"
2196
+ @element_objects = Array.new(length)
2197
+ for i in 0..length - 1 do
2198
+ @element_objects[i] = P.new(container, :jssh_name, elements[i])
2199
+ end
2200
+ end
2201
+ # include CommonCollection
2202
+ # def element_class; P; end
2203
+
2204
+ # private
2205
+ # def set_show_items
2206
+ # super
2207
+ # @show_attributes.delete( "name")
2208
+ # @show_attributes.add( "className" , 20)
2209
+ # end
2210
+
2211
+ end
2212
+
2213
+ #
2214
+ # Description:
2215
+ # Class for accessing all the span elements in the document.
2216
+ # It would normally only be accessed by the FireWatir::Container#spans method
2217
+ #
2218
+ class Spans < ElementCollections
2219
+ #
2220
+ # Description:
2221
+ # Initializes the instance of Spans class.
2222
+ #
2223
+ def initialize(container)
2224
+ #super(container, "span")
2225
+ @container = container
2226
+ elements = locate_tagged_elements("span")
2227
+ length = elements.length
2228
+ #puts "length is : #{length}"
2229
+ @element_objects = Array.new(length)
2230
+ for i in 0..length - 1 do
2231
+ @element_objects[i] = Span.new(container, :jssh_name, elements[i])
2232
+ end
2233
+ end
2234
+ # include CommonCollection
2235
+ # def element_class; Span; end
2236
+
2237
+ # private
2238
+ # def set_show_items
2239
+ # super
2240
+ # @show_attributes.delete( "name")
2241
+ # @show_attributes.add( "className" , 20)
2242
+ # end
2243
+
2244
+ end
2245
+
2246
+ #
2247
+ # Description:
2248
+ # Class for accessing all the div elements in the document.
2249
+ # It would normally only be accessed by the FireWatir::Container#divs method
2250
+ #
2251
+ class Divs < ElementCollections
2252
+ #
2253
+ # Description:
2254
+ # Initializes the instance of Divs class.
2255
+ #
2256
+ def initialize(container)
2257
+ #super(container, "div")
2258
+ @container = container
2259
+ elements = locate_tagged_elements("div")
2260
+ length = elements.length
2261
+ #puts "length is : #{length}"
2262
+ @element_objects = Array.new(length)
2263
+ for i in 0..length - 1 do
2264
+ @element_objects[i] = Div.new(container, :jssh_name, elements[i])
2265
+ end
2266
+ end
2267
+ # include CommonCollection
2268
+ # def element_class; Div; end
2269
+
2270
+ # private
2271
+ # def set_show_items
2272
+ # super
2273
+ # @show_attributes.delete( "name")
2274
+ # @show_attributes.add( "className" , 20)
2275
+ # end
2276
+
2277
+ end