watir 1.6.5 → 1.6.6.rc1

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