watir 1.9.2 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGES +27 -0
  2. data/VERSION +1 -1
  3. data/lib/watir/collections.rb +29 -387
  4. data/lib/watir/container.rb +14 -784
  5. data/lib/watir/dialogs/javascript.rb +7 -0
  6. data/lib/watir/element.rb +24 -4
  7. data/lib/watir/element_collections.rb +35 -57
  8. data/lib/watir/form.rb +13 -33
  9. data/lib/watir/frame.rb +14 -27
  10. data/lib/watir/html_element.rb +11 -3
  11. data/lib/watir/ie-class.rb +10 -1
  12. data/lib/watir/image.rb +3 -11
  13. data/lib/watir/input_elements.rb +11 -11
  14. data/lib/watir/link.rb +8 -15
  15. data/lib/watir/locator.rb +98 -73
  16. data/lib/watir/modal_dialog.rb +7 -1
  17. data/lib/watir/non_control_elements.rb +5 -89
  18. data/lib/watir/table.rb +46 -49
  19. data/unittests/checkbox_test.rb +39 -44
  20. data/unittests/checkbox_xpath_test.rb +2 -2
  21. data/unittests/css_test.rb +1 -1
  22. data/unittests/div_test.rb +43 -43
  23. data/unittests/div_xpath_test.rb +12 -12
  24. data/unittests/element_collections_test.rb +85 -0
  25. data/unittests/element_test.rb +4 -4
  26. data/unittests/form_test.rb +16 -19
  27. data/unittests/form_xpath_test.rb +6 -6
  28. data/unittests/frame_test.rb +114 -120
  29. data/unittests/html/multiple_specifiers.html +64 -0
  30. data/unittests/ie_test.rb +5 -5
  31. data/unittests/images_test.rb +12 -12
  32. data/unittests/index_specifier_test.rb +32 -0
  33. data/unittests/js_events_test.rb +3 -3
  34. data/unittests/links_multi_test.rb +4 -4
  35. data/unittests/links_test.rb +20 -20
  36. data/unittests/lists_test.rb +1 -1
  37. data/unittests/map_test.rb +1 -1
  38. data/unittests/multiple_specifiers_test.rb +29 -0
  39. data/unittests/no_wait_test.rb +2 -2
  40. data/unittests/pagecontainstext_test.rb +2 -2
  41. data/unittests/parent_child_test.rb +2 -2
  42. data/unittests/pre_test.rb +5 -5
  43. data/unittests/radios_test.rb +41 -60
  44. data/unittests/selectbox_test.rb +15 -15
  45. data/unittests/speed_settings_test.rb +2 -2
  46. data/unittests/table_and_tablerow_to_a_test.rb +7 -7
  47. data/unittests/table_test.rb +81 -94
  48. data/unittests/textfields_test.rb +26 -27
  49. data/unittests/windows/attach_to_new_window_test.rb +1 -1
  50. data/watir-rdoc.rb +1 -1
  51. data/watir.gemspec +1 -2
  52. metadata +34 -40
@@ -50,752 +50,13 @@ module Watir
50
50
  @container.wait(no_sleep)
51
51
  end
52
52
 
53
- # Determine the how and what when defaults are possible.
54
- def process_default(default_attribute, how, what)
55
- if what.nil? && String === how
56
- what = how
57
- how = default_attribute
58
- end
59
- return how, what
60
- end
61
- private :process_default
62
-
63
53
  def set_container container #:nodoc:
64
54
  @container = container
65
55
  @page_container = container.page_container
66
56
  end
67
57
 
68
- private
69
- def self.def_creator(method_name, klass_name=nil)
70
- klass_name ||= method_name.to_s.capitalize
71
- class_eval "def #{method_name}(how, what=nil)
72
- #{klass_name}.new(self, how, what)
73
- end"
74
- end
75
-
76
- def self.def_creator_with_default(method_name, default_symbol)
77
- klass_name = method_name.to_s.capitalize
78
- class_eval "def #{method_name}(how, what=nil)
79
- how, what = process_default :#{default_symbol}, how, what
80
- #{klass_name}.new(self, how, what)
81
- end"
82
- end
83
-
84
- #--
85
- # Factory Methods
86
- #++
87
58
  public
88
59
 
89
- # this method is the main way of accessing a frame
90
- # * how - how the frame is accessed. This can also just be the name of the frame.
91
- # * what - what we want to access.
92
- #
93
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
94
- #
95
- # returns a Frame object
96
- #
97
- # Typical usage:
98
- #
99
- # browser.frame(:index, 1)
100
- # browser.frame(:name, 'main_frame')
101
- # browser.frame('main_frame') # in this case, just a name is supplied
102
- def frame(how, what=nil)
103
- how, what = process_default :name, how, what
104
- Frame.new(self, how, what)
105
- end
106
-
107
- # this is the main method for accessing the frames iterator. Returns a Frames collection
108
- #
109
- # Typical usage:
110
- #
111
- # browser.frames.each { |f| puts f.src } # iterate through all the frames on the page
112
- # browser.frames[1].to_s # goto the first frame on the page
113
- # browser.frames.length # show how many frames are on the page.
114
- #
115
- def frames
116
- Frames.new(self)
117
- end
118
-
119
- # this method is used to access a form.
120
- # available ways of accessing it are, :index, :name, :id, :method, :action, :xpath
121
- # * how - symbol - What mecahnism we use to find the form, one of
122
- # the above. NOTE if what is not supplied this parameter is the NAME of the form
123
- # * what - String - the text associated with the symbol
124
- #
125
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
126
- #
127
- # returns a Form object
128
- def form(how, what=nil)
129
- how, what = process_default :name, how, what
130
- Form.new(self, how, what)
131
- end
132
-
133
- # this is the main method for accessing the forms iterator. Returns a Forms collection
134
- #
135
- # Typical usage:
136
- #
137
- # browser.forms.each { |f| puts f.src } # iterate through all the forms on the page
138
- # browser.forms[1].to_s # goto the first form on the page
139
- # browser.forms.length # show how many forms are on the page.
140
- #
141
- def forms
142
- Forms.new(self)
143
- end
144
-
145
- # This method is used to get a table from the page.
146
- # :index (1 based counting) and :id are supported.
147
- # NOTE :name is not supported, as the table tag does not have a name attribute. It is not part of the DOM.
148
- # :index can be used when there are multiple tables on a page.
149
- # :xpath can be used to select table using XPath query.
150
- # The first form can be accessed with :index 1, the second :index 2, etc.
151
- # * how - symbol - how we access the table, :index, :id, :xpath etc
152
- # * what - string the thing we are looking for, ex. id, index or xpath query, of the object we are looking for
153
- #
154
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
155
- #
156
- # returns a Table object
157
- def table(how, what=nil)
158
- Table.new(self, how, what)
159
- end
160
-
161
- # this is the main method for accessing the tables iterator. It returns a Tables object
162
- #
163
- # Typical usage:
164
- #
165
- # browser.tables.each { |t| puts t.to_s } # iterate through all the tables on the page
166
- # browser.tables[1].to_s # goto the first table on the page
167
- # browser.tables.length # show how many tables are on the page. Tables that are nested will be included in this
168
- def tables
169
- Tables.new(self)
170
- end
171
-
172
- # this method accesses a table cell.
173
- # how - symbol - how we access the cell, valid values are
174
- # :id - find the table cell with given id.
175
- # :xpath - find the table cell using xpath query.
176
- #
177
- # returns a TableCell Object
178
- def cell(how, what=nil)
179
- TableCell.new(self, how, what)
180
- end
181
- def cells
182
- TableCells.new(self)
183
- end
184
-
185
- # this method accesses a table row.
186
- # how - symbol - how we access the row, valid values are
187
- # :id - find the table row with given id.
188
- # :xpath - find the table row using xpath query.
189
- #
190
- # returns a TableRow object
191
- def row(how, what=nil)
192
- TableRow.new(self, how, what)
193
- end
194
- def rows
195
- TableRows.new(self)
196
- end
197
-
198
- # Access a modal web dialog, which is a PageContainer, like IE or Frame.
199
- # Returns a ModalDialog object.
200
- #
201
- # Typical Usage
202
- # browser.modal_dialog # access the modal dialog of ie
203
- # browser.modal_dialog(:title, 'Title') # access the modal dialog by title
204
- # browser.modal_dialog.modal_dialog # access a modal dialog's modal dialog XXX untested!
205
- #
206
- # This method will not work when
207
- # Watir/Ruby is run under a service (instead of a user).
208
- # Note: unlike Watir.attach, this returns before the page is assured to have
209
- # loaded.
210
-
211
- def modal_dialog(how=nil, what=nil)
212
- ModalDialog.new(self)
213
- end
214
-
215
- # This is the main method for accessing a button. Often declared as an <tt><input type = submit></tt> tag.
216
- # * how - symbol - how we access the button, :index, :id, :name etc
217
- # * what - string, integer or regular expression - what we are looking for,
218
- #
219
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
220
- #
221
- # Returns a Button object.
222
- #
223
- # Typical usage
224
- #
225
- # browser.button(:id, 'b_1') # access the button with an ID of b_1
226
- # browser.button(:name, 'verify_data') # access the button with a name of verify_data
227
- # browser.button(:value, 'Login') # access the button with a value (the text displayed on the button) of Login
228
- # browser.button(:caption, 'Login') # same as above
229
- # browser.button(:value, /Log/) # access the button that has text matching /Log/
230
- # browser.button(:index, 2) # access the second button on the page (1 based, so the first button is accessed with :index,1)
231
- # browser.button(:class, 'my_custom_button_class') # access the button with a class of my_custom_button_class
232
- # browser.button(:xpath, "//input[@value='Click Me']/") # access the button with a value of Click Me
233
- #
234
- # Accessing a Button nested within another element
235
- # browser.div(:class, 'xyz').button(:index, 2) # access a div of class xyz, and the 2nd button within that div
236
- #
237
- # If only a single parameter is supplied, then :value is used
238
- # browser.button('Click Me') # access the button with a value of Click Me
239
- def button(how, what=nil)
240
- how, what = process_default :value, how, what
241
- Button.new(self, how, what)
242
- end
243
-
244
- # this is the main method for accessing the buttons iterator. It returns a Buttons object
245
- #
246
- # Typical usage:
247
- #
248
- # browser.buttons.each { |b| puts b.to_s } # iterate through all the buttons on the page
249
- # browser.buttons[1].to_s # goto the first button on the page
250
- # browser.buttons.length # show how many buttons are on the page.
251
- def buttons
252
- Buttons.new(self)
253
- end
254
-
255
- # This is the main method for accessing a file field. Usually an <tt><input type = file></tt> HTML tag.
256
- # * how - symbol - how we access the field, valid values are
257
- # :index - find the file field using index
258
- # :id - find the file field using id attribute
259
- # :name - find the file field using name attribute
260
- # :xpath - find the file field using xpath query
261
- # * what - string, integer, regular expression, or xpath query - what we are looking for,
262
- #
263
- # returns a FileField object
264
- #
265
- # Typical Usage
266
- #
267
- # browser.file_field(:id, 'up_1') # access the file upload field with an ID of up_1
268
- # browser.file_field(:name, 'upload') # access the file upload field with a name of upload
269
- # browser.file_field(:index, 2) # access the second file upload on the page (1 based, so the first field is accessed with :index,1)
270
- #
271
- def file_field(how, what=nil)
272
- FileField.new(self, how, what)
273
- end
274
-
275
- def javascript_dialog(opts={})
276
- JavascriptDialog.new(opts)
277
- end
278
- alias :dialog :javascript_dialog
279
-
280
- # this is the main method for accessing the file_fields iterator. It returns a FileFields object
281
- #
282
- # Typical usage:
283
- #
284
- # browser.file_fields.each { |f| puts f.to_s } # iterate through all the file fields on the page
285
- # browser.file_fields[1].to_s # goto the first file field on the page
286
- # browser.file_fields.length # show how many file fields are on the page.
287
- def file_fields
288
- FileFields.new(self)
289
- end
290
-
291
- # This is the main method for accessing a text field. Usually an <tt><input type=text></tt> HTML tag.
292
- # or a text area - a <tt><textarea></tt> tag
293
- # * how - symbol - how we access the field, :index, :id, :name etc
294
- # * what - string, integer or regular expression - what we are looking for,
295
- #
296
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
297
- #
298
- # returns a TextField object
299
- #
300
- # Typical Usage
301
- #
302
- # browser.text_field(:id, 'user_name') # access the text field with an ID of user_name
303
- # browser.text_field(:name, 'address') # access the text field with a name of address
304
- # browser.text_field(:index, 2) # access the second text field on the page (1 based, so the first field is accessed with :index,1)
305
- # browser.text_field(:xpath, "//textarea[@id='user_name']/") # access the text field with an ID of user_name
306
- def text_field(how, what=nil)
307
- TextField.new(self, how, what)
308
- end
309
-
310
- # this is the method for accessing the text_fields iterator. It returns a Text_Fields object
311
- #
312
- # Typical usage:
313
- #
314
- # browser.text_fields.each { |t| puts t.to_s } # iterate through all the text fields on the page
315
- # browser.text_fields[1].to_s # goto the first text field on the page
316
- # browser.text_fields.length # show how many text field are on the page.
317
- def text_fields
318
- TextFields.new(self)
319
- end
320
-
321
- # This is the main method for accessing a hidden field. Usually an <tt><input type = hidden></tt> HTML tag
322
- #
323
- # * how - symbol - how we access the hidden field, :index, :id, :name etc
324
- # * what - string, integer or regular expression - what we are looking for,
325
- #
326
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
327
- #
328
- # returns a Hidden object
329
- #
330
- # Typical usage
331
- #
332
- # browser.hidden(:id, 'session_id') # access the hidden field with an ID of session_id
333
- # browser.hidden(:name, 'temp_value') # access the hidden field with a name of temp_value
334
- # browser.hidden(:index, 2) # access the second hidden field on the page (1 based, so the first field is accessed with :index,1)
335
- # browser.hidden(:xpath, "//input[@type='hidden' and @id='session_value']/") # access the hidden field with an ID of session_id
336
- def hidden(how, what=nil)
337
- Hidden.new(self, how, what)
338
- end
339
-
340
- # this is the method for accessing the hiddens iterator. It returns a Hiddens object
341
- #
342
- # Typical usage:
343
- #
344
- # browser.hiddens.each { |t| puts t.to_s } # iterate through all the hidden fields on the page
345
- # browser.hiddens[1].to_s # goto the first hidden field on the page
346
- # browser.hiddens.length # show how many hidden fields are on the page.
347
- def hiddens
348
- Hiddens.new(self)
349
- end
350
-
351
- # This is the main method for accessing a selection list. Usually a <tt><select></tt> HTML tag.
352
- # * how - symbol - how we access the selection list, :index, :id, :name etc
353
- # * what - string, integer or regular expression - what we are looking for,
354
- #
355
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
356
- #
357
- # returns a SelectList object
358
- #
359
- # Typical usage
360
- #
361
- # browser.select_list(:id, 'currency') # access the select box with an id of currency
362
- # browser.select_list(:name, 'country') # access the select box with a name of country
363
- # browser.select_list(:name, /n_/) # access the first select box whose name matches n_
364
- # browser.select_list(:index, 2) # access the second select box on the page (1 based, so the first field is accessed with :index,1)
365
- # browser.select(:xpath, "//select[@id='currency']/") # access the select box with an id of currency
366
- def select_list(how, what=nil)
367
- SelectList.new(self, how, what)
368
- end
369
-
370
- # this is the method for accessing the select lists iterator. Returns a SelectLists object
371
- #
372
- # Typical usage:
373
- #
374
- # browser.select_lists.each { |s| puts s.to_s } # iterate through all the select boxes on the page
375
- # browser.select_lists[1].to_s # goto the first select boxes on the page
376
- # browser.select_lists.length # show how many select boxes are on the page.
377
- def select_lists
378
- SelectLists.new(self)
379
- end
380
-
381
- # This is the main method for accessing a check box. Usually an <tt><input type = checkbox></tt> HTML tag.
382
- #
383
- # * how - symbol - how we access the check box - :index, :id, :name etc
384
- # * what - string, integer or regular expression - what we are looking for,
385
- # * value - string - when there are multiple objects with different value attributes, this can be used to find the correct object
386
- #
387
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
388
- #
389
- # returns a CheckBox object
390
- #
391
- # Typical usage
392
- #
393
- # browser.checkbox(:id, 'send_email') # access the check box with an id of send_mail
394
- # browser.checkbox(:name, 'send_copy') # access the check box with a name of send_copy
395
- # browser.checkbox(:name, /n_/) # access the first check box whose name matches n_
396
- # browser.checkbox(:index, 2) # access the second check box on the page (1 based, so the first field is accessed with :index,1)
397
- #
398
- # In many instances, checkboxes on an html page have the same name, but are identified by different values. An example is shown next.
399
- #
400
- # <input type = checkbox name = email_frequency value = 'daily' > Daily Email
401
- # <input type = checkbox name = email_frequency value = 'Weekly'> Weekly Email
402
- # <input type = checkbox name = email_frequency value = 'monthly'>Monthly Email
403
- #
404
- # Watir can access these using the following:
405
- #
406
- # browser.checkbox(:id, 'day_to_send', 'monday') # access the check box with an id of day_to_send and a value of monday
407
- # browser.checkbox(:name,'email_frequency', 'weekly') # access the check box with a name of email_frequency and a value of 'weekly'
408
- # browser.checkbox(:xpath, "//input[@name='email_frequency' and @value='daily']/") # access the checkbox with a name of email_frequency and a value of 'daily'
409
- def checkbox(how, what=nil, value=nil) # should be "check_box" ?
410
- CheckBox.new(self, how, what, value)
411
- end
412
-
413
- # this is the method for accessing the check boxes iterator. Returns a CheckBoxes object
414
- #
415
- # Typical usage:
416
- #
417
- # browser.checkboxes.each { |c| puts c.to_s } # iterate through all the check boxes on the page
418
- # browser.checkboxes[1].to_s # goto the first check box on the page
419
- # browser.checkboxes.length # show how many check boxes are on the page.
420
- def checkboxes
421
- CheckBoxes.new(self)
422
- end
423
-
424
- # This is the main method for accessing a radio button. Usually an <tt><input type = radio></tt> HTML tag.
425
- # * how - symbol - how we access the radio button, :index, :id, :name etc
426
- # * what - string, integer or regular expression - what we are looking for,
427
- # * value - string - when there are multiple objects with different value attributes, this can be used to find the correct object
428
- #
429
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
430
- #
431
- # returns a Radio object
432
- #
433
- # Typical usage
434
- #
435
- # browser.radio(:id, 'send_email') # access the radio button with an id of currency
436
- # browser.radio(:name, 'send_copy') # access the radio button with a name of country
437
- # browser.radio(:name, /n_/) # access the first radio button whose name matches n_
438
- # browser.radio(:index, 2) # access the second radio button on the page (1 based, so the first field is accessed with :index,1)
439
- #
440
- # In many instances, radio buttons on an html page have the same name, but are identified by different values. An example is shown next.
441
- #
442
- # <input type="radio" name="email_frequency" value="daily">Daily Email</input>
443
- # <input type="radio" name="email_frequency" value="weekly">Weekly Email</input>
444
- # <input type="radio" name="email_frequency" value="monthly">Monthly Email</input>
445
- #
446
- # Watir can access these using the following:
447
- #
448
- # browser.radio(:id, 'day_to_send', 'monday') # access the radio button with an id of day_to_send and a value of monday
449
- # browser.radio(:name,'email_frequency', 'weekly') # access the radio button with a name of email_frequency and a value of 'weekly'
450
- # browser.radio(:xpath, "//input[@name='email_frequency' and @value='daily']/") # access the radio button with a name of email_frequency and a value of 'daily'
451
- def radio(how, what=nil, value=nil)
452
- Radio.new(self, how, what, value)
453
- end
454
-
455
- # This is the method for accessing the radio buttons iterator. Returns a Radios object
456
- #
457
- # Typical usage:
458
- #
459
- # browser.radios.each { |r| puts r.to_s } # iterate through all the radio buttons on the page
460
- # browser.radios[1].to_s # goto the first radio button on the page
461
- # browser.radios.length # show how many radio buttons are on the page.
462
- #
463
- def radios
464
- Radios.new(self)
465
- end
466
-
467
- # This is the main method for accessing a link.
468
- # * how - symbol - how we access the link, :index, :id, :name, :title, :text, :url
469
- # * what - string, integer or regular expression - what we are looking for,
470
- #
471
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
472
- #
473
- # returns a Link object
474
- #
475
- # Typical Usage
476
- #
477
- # browser.link(:url, /login/) # access the first link whose url matches login. We can use a string in place of the regular expression
478
- # # but the complete path must be used, browser.link(:url, 'http://myserver.com/my_path/login.asp')
479
- # browser.link(:index,2) # access the second link on the page
480
- # browser.link(:title, "Picture") # access a link using the tool tip
481
- # browser.link(:text, 'Click Me') # access the link that has Click Me as its text
482
- # browser.link(:xpath, "//a[contains(.,'Click Me')]/") # access the link with Click Me as its text
483
- def link(how, what=nil)
484
- Link.new(self, how, what)
485
- end
486
-
487
- # This is the main method for accessing the links collection. Returns a Links object
488
- #
489
- # Typical usage:
490
- #
491
- # browser.links.each { |l| puts l.to_s } # iterate through all the links on the page
492
- # browser.links[1].to_s # goto the first link on the page
493
- # browser.links.length # show how many links are on the page.
494
- #
495
- def links
496
- Links.new(self)
497
- end
498
-
499
- # This is the main method for accessing li tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/map.asp?frame=true
500
- # * how - symbol - how we access the li,
501
- # * what - string, integer or regular expression - what we are looking for,
502
- #
503
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
504
- #
505
- # returns a li object
506
- #
507
- # Typical Usage
508
- #
509
- # browser.li(:id, /list/) # access the first li that matches list.
510
- # browser.li(:index,2) # access the second li on the page
511
- # browser.li(:title, "A Picture") # access a li using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
512
- #
513
- # def li(how, what=nil)
514
- # return Li.new(self, how, what)
515
- # end
516
-
517
- # this is the main method for accessing the lis iterator.
518
- #
519
- # Returns a lis object
520
- #
521
- # Typical usage:
522
- #
523
- # browser.lis.each { |s| puts s.to_s } # iterate through all the lis on the page
524
- # browser.lis[1].to_s # goto the first li on the page
525
- # browser.lis.length # show how many lis are on the page.
526
- #
527
- def lis
528
- return Lis.new(self)
529
- end
530
-
531
-
532
- # This is the main method for accessing map tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/map.asp?frame=true
533
- # * how - symbol - how we access the map,
534
- # * what - string, integer or regular expression - what we are looking for,
535
- #
536
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
537
- #
538
- # returns a map object
539
- #
540
- # Typical Usage
541
- #
542
- # browser.map(:id, /list/) # access the first map that matches list.
543
- # browser.map(:index,2) # access the second map on the page
544
- # browser.map(:title, "A Picture") # access a map using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
545
- #
546
- def map(how, what=nil)
547
- return Map.new(self, how, what)
548
- end
549
-
550
- # this is the main method for accessing the maps iterator.
551
- #
552
- # Returns a maps object
553
- #
554
- # Typical usage:
555
- #
556
- # browser.maps.each { |s| puts s.to_s } # iterate through all the maps on the page
557
- # browser.maps[1].to_s # goto the first map on the page
558
- # browser.maps.length # show how many maps are on the page.
559
- #
560
- def maps
561
- return Maps.new(self)
562
- end
563
-
564
- # This is the main method for accessing area tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/area.asp?frame=true
565
- # * how - symbol - how we access the area
566
- # * what - string, integer or regular expression - what we are looking for,
567
- #
568
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
569
- #
570
- # returns a area object
571
- #
572
- # Typical Usage
573
- #
574
- # browser.area(:id, /list/) # access the first area that matches list.
575
- # browser.area(:index,2) # access the second area on the page
576
- # browser.area(:title, "A Picture") # access a area using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
577
- #
578
- def area(how, what=nil)
579
- return Area.new(self, how, what)
580
- end
581
-
582
- # this is the main method for accessing the areas iterator.
583
- #
584
- # Returns a areas object
585
- #
586
- # Typical usage:
587
- #
588
- # browser.areas.each { |s| puts s.to_s } # iterate through all the areas on the page
589
- # browser.areas[1].to_s # goto the first area on the page
590
- # browser.areas.length # show how many areas are on the page.
591
- #
592
- def areas
593
- return Areas.new(self)
594
- end
595
-
596
- # This is the main method for accessing images - normally an <tt><img src="image.gif"></tt> HTML tag.
597
- # * how - symbol - how we access the image, :index, :id, :name, :src, :title or :alt are supported
598
- # * what - string, integer or regular expression - what we are looking for,
599
- #
600
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
601
- #
602
- # returns an Image object
603
- #
604
- # Typical Usage
605
- #
606
- # browser.image(:src, /myPic/) # access the first image that matches myPic. We can use a string in place of the regular expression
607
- # # but the complete path must be used, browser.image(:src, 'http://myserver.com/my_path/my_image.jpg')
608
- # browser.image(:index,2) # access the second image on the page
609
- # browser.image(:alt, "A Picture") # access an image using the alt text
610
- # browser.image(:xpath, "//img[@alt='A Picture']/") # access an image using the alt text
611
- #
612
- def image(how, what=nil)
613
- Image.new(self, how, what)
614
- end
615
-
616
- # This is the main method for accessing the images collection. Returns an Images object
617
- #
618
- # Typical usage:
619
- #
620
- # browser.images.each { |i| puts i.to_s } # iterate through all the images on the page
621
- # browser.images[1].to_s # goto the first image on the page
622
- # browser.images.length # show how many images are on the page.
623
- #
624
- def images
625
- Images.new(self)
626
- end
627
-
628
- # This is the main method for accessing JavaScript popups.
629
- # returns a PopUp object
630
- def popup # BUG this should not be on the container object!
631
- PopUp.new(self)
632
- end
633
-
634
-
635
- # this is the main method for accessing the divs iterator. Returns a Divs collection
636
- #
637
- # Typical usage:
638
- #
639
- # browser.divs.each { |d| puts d.to_s } # iterate through all the divs on the page
640
- # browser.divs[1].to_s # goto the first div on the page
641
- # browser.divs.length # show how many divs are on the page.
642
- #
643
- def divs
644
- Divs.new(self)
645
- end
646
-
647
- # this is the main method for accessing the dls iterator. Returns a Dls collection
648
- #
649
- # Typical usage:
650
- #
651
- # browser.dls.each { |d| puts d.to_s } # iterate through all the dls on the page
652
- # browser.dls[1].to_s # goto the first dl on the page
653
- # browser.dls.length # show how many dls are on the page.
654
- #
655
- def dls
656
- Dls.new(self)
657
- end
658
-
659
- # this is the main method for accessing the dds iterator. Returns a Dds collection
660
- #
661
- # Typical usage:
662
- #
663
- # browser.dds.each { |d| puts d.to_s } # iterate through all the dds on the page
664
- # browser.dds[1].to_s # goto the first dd on the page
665
- # browser.dds.length # show how many dds are on the page.
666
- #
667
- def dds
668
- Dds.new(self)
669
- end
670
-
671
- # this is the main method for accessing the dts iterator. Returns a Dts collection
672
- #
673
- # Typical usage:
674
- #
675
- # browser.dts.each { |d| puts d.to_s } # iterate through all the dts on the page
676
- # browser.dts[1].to_s # goto the first dt on the page
677
- # browser.dts.length # show how many dts are on the page.
678
- #
679
- def dts
680
- Dts.new(self)
681
- end
682
-
683
- # this is the main method for accessing the ems iterator. Returns a Ems collection
684
- #
685
- # Typical usage:
686
- #
687
- # browser.ems.each { |d| puts d.to_s } # iterate through all the ems on the page
688
- # browser.ems[1].to_s # goto the first em on the page
689
- # browser.ems.length # show how many ems are on the page.
690
- #
691
- def ems
692
- Ems.new(self)
693
- end
694
-
695
- # this is the main method for accessing the spans iterator.
696
- #
697
- # Returns a Spans object
698
- #
699
- # Typical usage:
700
- #
701
- # browser.spans.each { |s| puts s.to_s } # iterate through all the spans on the page
702
- # browser.spans[1].to_s # goto the first span on the page
703
- # browser.spans.length # show how many spans are on the page.
704
- #
705
- def spans
706
- Spans.new(self)
707
- end
708
-
709
- # this is the main method for accessing the Strongs iterator.
710
- #
711
- # Returns a Strongs object
712
- #
713
- # Typical usage:
714
- #
715
- # browser.strongs.each { |s| puts s.to_s } # iterate through all the strongs on the page
716
- # browser.strongs[1].to_s # goto the first strong on the page
717
- # browser.strongs.length # show how many strongs are on the page.
718
- #
719
- def strongs
720
- return Strongs.new(self)
721
- end
722
-
723
-
724
- # this is the main method for accessing the ps iterator.
725
- #
726
- # Returns a Ps object
727
- #
728
- # Typical usage:
729
- #
730
- # browser.ps.each { |p| puts p.to_s } # iterate through all the p tags on the page
731
- # browser.ps[1].to_s # goto the first p tag on the page
732
- # browser.ps.length # show how many p tags are on the page.
733
- #
734
- def ps
735
- Ps.new(self)
736
- end
737
-
738
- # this is the main method for accessing the ps iterator.
739
- #
740
- # Returns a Pres object
741
- #
742
- # Typical usage:
743
- #
744
- # browser.pres.each { |pre| puts pre.to_s } # iterate through all the pre tags on the page
745
- # browser.pres[1].to_s # goto the first pre tag on the page
746
- # browser.pres.length # show how many pre tags are on the page.
747
- #
748
- def pres
749
- Pres.new(self)
750
- end
751
-
752
- # this is the main method for accessing the labels iterator. It returns a Labels object
753
- #
754
- # Returns a Labels object
755
- #
756
- # Typical usage:
757
- #
758
- # browser.labels.each { |l| puts l.to_s } # iterate through all the labels on the page
759
- # browser.labels[1].to_s # goto the first label on the page
760
- # browser.labels.length # show how many labels are on the page.
761
- #
762
- def labels
763
- Labels.new(self)
764
- end
765
-
766
-
767
- # This is the main method for accessing a generic element with a given attibute
768
- # * how - symbol - how we access the element. Supports all values except :index and :xpath
769
- # * what - string, integer or regular expression - what we are looking for,
770
- #
771
- # Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
772
- #
773
- # returns an Watir::Element object
774
- #
775
- # Typical Usage
776
- #
777
- # ie.element(:class, /foo/) # access the first element with class 'foo'. We can use a string in place of the regular expression
778
- # ie.element(:id, "11") # access the first element that matches an id
779
- def element(how, what)
780
- return HTMLElement.new(self, how, what)
781
- end
782
-
783
- # this is the main method for accessing generic html elements by an attribute
784
- #
785
- # Returns a HTMLElements object
786
- #
787
- # Typical usage:
788
- #
789
- # ie.elements(:class, 'test').each { |l| puts l.to_s } # iterate through all elements of a given attribute
790
- # ie.elements(:alt, 'foo')[1].to_s # get the first element of a given attribute
791
- # ie.elements(:id, 'foo').length # show how many elements are foung in the collection
792
- #
793
- def elements(how, what)
794
- return HTMLElements.new(self, how, what)
795
- end
796
-
797
- #--
798
- #
799
60
  # Searching for Page Elements
800
61
  # Not for external consumption
801
62
  #
@@ -833,59 +94,28 @@ module Watir
833
94
  puts s
834
95
  end
835
96
 
97
+ # Locator Methods
836
98
  #
837
- # Locator Methods
838
- #
839
-
840
- # Returns the specified ole object for input elements on a web page.
841
- #
842
- # This method is used internally by Watir and should not be used externally. It cannot be marked as private because of the way mixins and inheritance work in watir
843
- #
844
- # * how - symbol - the way we look for the object. Supported values are
845
- # - :name
846
- # - :id
847
- # - :index
848
- # - :value etc
849
- # * what - string that we are looking for, ex. the name, or id tag attribute or index of the object we are looking for.
850
- # * types - what object types we will look at.
851
- # * value - used for objects that have one name, but many values. ex. radio lists and checkboxes
852
- def locate_input_element(how, what, types, value=nil, klass=nil)
853
- case how
854
- when :xpath
855
- return element_by_xpath(what)
856
- when :css
857
- return element_by_css(what)
858
- when :ole_object
859
- return what
860
- end
861
- # else:
862
-
863
- locator = InputElementLocator.new self, types
864
- locator.specifier = [how, what, value]
99
+ # Not for external use, but cannot set to private due to usages in Element
100
+ # classes.
101
+
102
+ def input_element_locator(how, what, types, klass=nil)
103
+ locator = InputElementLocator.new self, types, klass
104
+ locator.set_specifier how, what
865
105
  locator.document = document
866
106
  return locator.element if locator.fast_locate
867
- # todo: restrict search to elements.getElementsByTag('INPUT'); faster
868
107
  locator.elements = ole_inner_elements if locator.elements.nil?
869
- locator.klass = klass if klass
870
- locator.locate
871
- end
872
-
873
- # abstract method for locating an element using a CSS selector expression
874
- def element_by_css(selector)
875
- raise MissingWayOfFindingObjectException, "CSS selectors not yet supported for #{self.class.name}"
108
+ locator
876
109
  end
877
110
 
878
- # returns the ole object for the specified element
879
- def locate_tagged_element(tag, how, what)
880
- locator = TaggedElementLocator.new(self, tag)
111
+ def tagged_element_locator(tag, how, what, klass=nil)
112
+ locator = TaggedElementLocator.new(self, tag, klass)
881
113
  locator.set_specifier(how, what)
882
- locator.locate
114
+ locator
883
115
  end
884
-
885
- # returns the the locator object so you can iterate
886
- # over the elements using #each
887
- def locate_all_elements(how, what)
888
- locator = ElementLocator.new(self)
116
+
117
+ def locator_for(locator_class, how, what)
118
+ locator = locator_class.new(self)
889
119
  locator.set_specifier(how, what)
890
120
  locator
891
121
  end