watir 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/readme.rb +20 -12
- data/unittests/html/table1.html +41 -1
- data/unittests/links_test.rb +2 -2
- data/unittests/navigate_test.rb +2 -2
- data/unittests/parent_child_test.rb +0 -15
- data/unittests/table_test.rb +5 -2
- data/unittests/textarea_test.rb +55 -39
- data/unittests/windows/iedialog_test.rb +2 -2
- data/watir.rb +20 -4386
- data/watir/{elements.rb → bonus-elements.rb} +0 -0
- data/watir/collections.rb +317 -0
- data/watir/container.rb +883 -0
- data/watir/element.rb +306 -0
- data/watir/element_collections.rb +82 -0
- data/watir/form.rb +151 -0
- data/watir/frame.rb +60 -0
- data/watir/ie.rb +973 -0
- data/watir/image.rb +131 -0
- data/watir/input_elements.rb +518 -0
- data/watir/link.rb +65 -0
- data/watir/locator.rb +79 -0
- data/watir/logger.rb +19 -0
- data/watir/modal_dialog.rb +123 -0
- data/watir/non_control_elements.rb +91 -0
- data/watir/page-container.rb +106 -0
- data/watir/popup.rb +30 -0
- data/watir/table.rb +356 -0
- data/watir/win32.rb +29 -0
- metadata +21 -3
File without changes
|
@@ -0,0 +1,317 @@
|
|
1
|
+
module Watir
|
2
|
+
#--
|
3
|
+
# These classes are not for public consumption, so we switch off rdoc
|
4
|
+
|
5
|
+
# presumes element_class or element_tag is defined
|
6
|
+
# for subclasses of ElementCollections
|
7
|
+
module CommonCollection
|
8
|
+
def element_tag
|
9
|
+
element_class::TAG
|
10
|
+
end
|
11
|
+
def length
|
12
|
+
@container.document.getElementsByTagName(element_tag).length
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# This class is used as part of the .show method of the iterators class
|
17
|
+
# it would not normally be used by a user
|
18
|
+
class AttributeLengthPairs
|
19
|
+
|
20
|
+
# This class is used as part of the .show method of the iterators class
|
21
|
+
# it would not normally be used by a user
|
22
|
+
class AttributeLengthHolder
|
23
|
+
attr_accessor :attribute
|
24
|
+
attr_accessor :length
|
25
|
+
|
26
|
+
def initialize(attrib, length)
|
27
|
+
@attribute = attrib
|
28
|
+
@length = length
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(attrib=nil, length=nil)
|
33
|
+
@attr=[]
|
34
|
+
add(attrib, length) if attrib
|
35
|
+
@index_counter = 0
|
36
|
+
end
|
37
|
+
|
38
|
+
# BUG: Untested. (Null implementation passes all tests.)
|
39
|
+
def add(attrib, length)
|
40
|
+
@attr << AttributeLengthHolder.new(attrib, length)
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete(attrib)
|
44
|
+
item_to_delete = nil
|
45
|
+
@attr.each_with_index do |e,i|
|
46
|
+
item_to_delete = i if e.attribute == attrib
|
47
|
+
end
|
48
|
+
@attr.delete_at(item_to_delete) unless item_to_delete == nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def next
|
52
|
+
temp = @attr[@index_counter]
|
53
|
+
@index_counter += 1
|
54
|
+
return temp
|
55
|
+
end
|
56
|
+
|
57
|
+
def each
|
58
|
+
0.upto(@attr.length-1) { |i | yield @attr[i] }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# resume rdoc
|
63
|
+
#++
|
64
|
+
|
65
|
+
# this class accesses the buttons in the document as a collection
|
66
|
+
# it would normally only be accessed by the Watir::Container#buttons method
|
67
|
+
class Buttons < ElementCollections
|
68
|
+
def element_class; Button; end
|
69
|
+
def length
|
70
|
+
get_length_of_input_objects(["button", "submit", "image"])
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def set_show_items
|
75
|
+
super
|
76
|
+
@show_attributes.add("disabled", 9)
|
77
|
+
@show_attributes.add("value", 20)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# this class accesses the file fields in the document as a collection
|
82
|
+
# normal access is via the Container#file_fields method
|
83
|
+
class FileFields < ElementCollections
|
84
|
+
def element_class; FileField; end
|
85
|
+
def length
|
86
|
+
get_length_of_input_objects(["file"])
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def set_show_items
|
91
|
+
super
|
92
|
+
@show_attributes.add("disabled", 9)
|
93
|
+
@show_attributes.add("value", 20)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# this class accesses the check boxes in the document as a collection
|
98
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#checkboxes method
|
99
|
+
class CheckBoxes < ElementCollections
|
100
|
+
def element_class; CheckBox; end
|
101
|
+
def length
|
102
|
+
get_length_of_input_objects("checkbox")
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
def iterator_object(i)
|
107
|
+
@container.checkbox(:index, i + 1)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# this class accesses the radio buttons in the document as a collection
|
112
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#radios method
|
113
|
+
class Radios < ElementCollections
|
114
|
+
def element_class; Radio; end
|
115
|
+
def length
|
116
|
+
get_length_of_input_objects("radio")
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
def iterator_object(i)
|
121
|
+
@container.radio(:index, i + 1)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# this class accesses the select boxes in the document as a collection
|
126
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#select_lists method
|
127
|
+
class SelectLists < ElementCollections
|
128
|
+
include CommonCollection
|
129
|
+
def element_class; SelectList; end
|
130
|
+
def element_tag; 'SELECT'; end
|
131
|
+
end
|
132
|
+
|
133
|
+
# this class accesses the links in the document as a collection
|
134
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#links method
|
135
|
+
class Links < ElementCollections
|
136
|
+
include CommonCollection
|
137
|
+
def element_class; Link; end
|
138
|
+
def element_tag; 'A'; end
|
139
|
+
|
140
|
+
private
|
141
|
+
def set_show_items
|
142
|
+
super
|
143
|
+
@show_attributes.add("href", 60)
|
144
|
+
@show_attributes.add("innerText", 60)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
class Lis < ElementCollections
|
149
|
+
include Watir::CommonCollection
|
150
|
+
def element_class; Li; end
|
151
|
+
|
152
|
+
def set_show_items
|
153
|
+
super
|
154
|
+
@show_attributes.delete( "name")
|
155
|
+
@show_attributes.add( "className" , 20)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
class Map < NonControlElement
|
160
|
+
TAG = 'MAP'
|
161
|
+
end
|
162
|
+
|
163
|
+
class Area < NonControlElement
|
164
|
+
TAG = 'AREA'
|
165
|
+
end
|
166
|
+
|
167
|
+
# this class accesses the maps in the document as a collection
|
168
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#maps method
|
169
|
+
class Maps < ElementCollections
|
170
|
+
include CommonCollection
|
171
|
+
def element_class; Map; end
|
172
|
+
def element_tag; 'MAP'; end
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
# this class accesses the areas in the document as a collection
|
177
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#areas method
|
178
|
+
class Areas < ElementCollections
|
179
|
+
include CommonCollection
|
180
|
+
def element_class; Area; end
|
181
|
+
def element_tag; 'AREA'; end
|
182
|
+
end
|
183
|
+
|
184
|
+
# this class accesses the imnages in the document as a collection
|
185
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#images method
|
186
|
+
class Images < ElementCollections
|
187
|
+
def element_class; Image; end
|
188
|
+
def length
|
189
|
+
@container.document.images.length
|
190
|
+
end
|
191
|
+
|
192
|
+
private
|
193
|
+
def set_show_items
|
194
|
+
super
|
195
|
+
@show_attributes.add("src", 60)
|
196
|
+
@show_attributes.add("alt", 30)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# this class accesses the text fields in the document as a collection
|
201
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#text_fields method
|
202
|
+
class TextFields < ElementCollections
|
203
|
+
def element_class; TextField; end
|
204
|
+
def length
|
205
|
+
# text areas are also included in the TextFields, but we need to get them seperately
|
206
|
+
get_length_of_input_objects(["text", "password"]) +
|
207
|
+
@container.document.getElementsByTagName("textarea").length
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# this class accesses the hidden fields in the document as a collection
|
212
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#hiddens method
|
213
|
+
class Hiddens < ElementCollections
|
214
|
+
def element_class; Hidden; end
|
215
|
+
def length
|
216
|
+
get_length_of_input_objects("hidden")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# this class accesses the text fields in the document as a collection
|
221
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#tables method
|
222
|
+
class Tables < ElementCollections
|
223
|
+
include CommonCollection
|
224
|
+
def element_class; Table; end
|
225
|
+
def element_tag; 'TABLE'; end
|
226
|
+
|
227
|
+
private
|
228
|
+
def set_show_items
|
229
|
+
super
|
230
|
+
@show_attributes.delete("name")
|
231
|
+
end
|
232
|
+
end
|
233
|
+
# this class accesses the table rows in the document as a collection
|
234
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#rows method
|
235
|
+
class TableRows < ElementCollections
|
236
|
+
include CommonCollection
|
237
|
+
def element_class; TableRow; end
|
238
|
+
def element_tag; 'TR'; end
|
239
|
+
end
|
240
|
+
# this class accesses the table cells in the document as a collection
|
241
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#cells method
|
242
|
+
class TableCells < ElementCollections
|
243
|
+
include CommonCollection
|
244
|
+
def element_class; TableCell; end
|
245
|
+
def element_tag; 'TD'; end
|
246
|
+
end
|
247
|
+
# this class accesses the labels in the document as a collection
|
248
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#labels method
|
249
|
+
class Labels < ElementCollections
|
250
|
+
include CommonCollection
|
251
|
+
def element_class; Label; end
|
252
|
+
def element_tag; 'LABEL'; end
|
253
|
+
|
254
|
+
private
|
255
|
+
def set_show_items
|
256
|
+
super
|
257
|
+
@show_attributes.add("htmlFor", 20)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
# this class accesses the pre tags in the document as a collection
|
262
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#pres method
|
263
|
+
class Pres < ElementCollections
|
264
|
+
include CommonCollection
|
265
|
+
def element_class; Pre; end
|
266
|
+
|
267
|
+
private
|
268
|
+
def set_show_items
|
269
|
+
super
|
270
|
+
@show_attributes.delete("name")
|
271
|
+
@show_attributes.add("className", 20)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
# this class accesses the p tags in the document as a collection
|
276
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#ps method
|
277
|
+
class Ps < ElementCollections
|
278
|
+
include CommonCollection
|
279
|
+
def element_class; P; end
|
280
|
+
|
281
|
+
private
|
282
|
+
def set_show_items
|
283
|
+
super
|
284
|
+
@show_attributes.delete("name")
|
285
|
+
@show_attributes.add("className", 20)
|
286
|
+
end
|
287
|
+
|
288
|
+
end
|
289
|
+
# this class accesses the spans in the document as a collection
|
290
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#spans method
|
291
|
+
class Spans < ElementCollections
|
292
|
+
include CommonCollection
|
293
|
+
def element_class; Span; end
|
294
|
+
|
295
|
+
private
|
296
|
+
def set_show_items
|
297
|
+
super
|
298
|
+
@show_attributes.delete("name")
|
299
|
+
@show_attributes.add("className", 20)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# this class accesses the divs in the document as a collection
|
304
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#divs method
|
305
|
+
class Divs < ElementCollections
|
306
|
+
include CommonCollection
|
307
|
+
def element_class; Div; end
|
308
|
+
|
309
|
+
private
|
310
|
+
def set_show_items
|
311
|
+
super
|
312
|
+
@show_attributes.delete("name")
|
313
|
+
@show_attributes.add("className", 20)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
data/watir/container.rb
ADDED
@@ -0,0 +1,883 @@
|
|
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
|
+
# The color we want to use for the active object. This can be any valid web-friendly color.
|
29
|
+
attr_accessor :activeObjectHighLightColor
|
30
|
+
# The PageContainer object containing this element
|
31
|
+
attr_accessor :page_container
|
32
|
+
|
33
|
+
def copy_test_config(container) # only used by form and frame
|
34
|
+
@typingspeed = container.typingspeed
|
35
|
+
@activeObjectHighLightColor = container.activeObjectHighLightColor
|
36
|
+
end
|
37
|
+
private :copy_test_config
|
38
|
+
|
39
|
+
# Write the specified string to the log.
|
40
|
+
def log(what)
|
41
|
+
@container.logger.debug(what) if @logger
|
42
|
+
end
|
43
|
+
|
44
|
+
# Wait until Internet Explorer has finished loading the page.
|
45
|
+
def wait(no_sleep=false)
|
46
|
+
@container.wait(no_sleep)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Determine the how and what when defaults are possible.
|
50
|
+
def process_default(default_attribute, how, what)
|
51
|
+
if how.class == String && what == nil
|
52
|
+
what = how
|
53
|
+
how = default_attribute
|
54
|
+
end
|
55
|
+
return how, what
|
56
|
+
end
|
57
|
+
private :process_default
|
58
|
+
|
59
|
+
def set_container container
|
60
|
+
@container = container
|
61
|
+
@page_container = container.page_container
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
def self.def_creator(method_name, klass_name=nil)
|
66
|
+
klass_name ||= method_name.to_s.capitalize
|
67
|
+
class_eval "def #{method_name}(how, what=nil)
|
68
|
+
#{klass_name}.new(self, how, what)
|
69
|
+
end"
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.def_creator_with_default(method_name, default_symbol)
|
73
|
+
klass_name = method_name.to_s.capitalize
|
74
|
+
class_eval "def #{method_name}(how, what=nil)
|
75
|
+
how, what = process_default :#{default_symbol}, how, what
|
76
|
+
#{klass_name}.new(self, how, what)
|
77
|
+
end"
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Factory Methods
|
82
|
+
#
|
83
|
+
|
84
|
+
# this method is the main way of accessing a frame
|
85
|
+
# * how - how the frame is accessed. This can also just be the name of the frame.
|
86
|
+
# * what - what we want to access.
|
87
|
+
#
|
88
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
89
|
+
#
|
90
|
+
# returns a Frame object
|
91
|
+
#
|
92
|
+
# Typical usage:
|
93
|
+
#
|
94
|
+
# ie.frame(:index, 1)
|
95
|
+
# ie.frame(:name, 'main_frame')
|
96
|
+
# ie.frame('main_frame') # in this case, just a name is supplied
|
97
|
+
public
|
98
|
+
def frame(how, what=nil)
|
99
|
+
how, what = process_default :name, how, what
|
100
|
+
Frame.new(self, how, what)
|
101
|
+
end
|
102
|
+
|
103
|
+
# this method is used to access a form.
|
104
|
+
# available ways of accessing it are, :index, :name, :id, :method, :action, :xpath
|
105
|
+
# * how - symbol - What mecahnism we use to find the form, one of
|
106
|
+
# the above. NOTE if what is not supplied this parameter is the NAME of the form
|
107
|
+
# * what - String - the text associated with the symbol
|
108
|
+
#
|
109
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
110
|
+
#
|
111
|
+
# returns a Form object
|
112
|
+
def form(how, what=nil)
|
113
|
+
how, what = process_default :name, how, what
|
114
|
+
Form.new(self, how, what)
|
115
|
+
end
|
116
|
+
|
117
|
+
# This method is used to get a table from the page.
|
118
|
+
# :index (1 based counting) and :id are supported.
|
119
|
+
# NOTE :name is not supported, as the table tag does not have a name attribute. It is not part of the DOM.
|
120
|
+
# :index can be used when there are multiple tables on a page.
|
121
|
+
# :xpath can be used to select table using XPath query.
|
122
|
+
# The first form can be accessed with :index 1, the second :index 2, etc.
|
123
|
+
# * how - symbol - how we access the table, :index, :id, :xpath etc
|
124
|
+
# * what - string the thing we are looking for, ex. id, index or xpath query, of the object we are looking for
|
125
|
+
#
|
126
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
127
|
+
#
|
128
|
+
# returns a Table object
|
129
|
+
def table(how, what=nil)
|
130
|
+
Table.new(self, how, what)
|
131
|
+
end
|
132
|
+
|
133
|
+
# this is the main method for accessing the tables iterator. It returns a Tables object
|
134
|
+
#
|
135
|
+
# Typical usage:
|
136
|
+
#
|
137
|
+
# ie.tables.each { |t| puts t.to_s } # iterate through all the tables on the page
|
138
|
+
# ie.tables[1].to_s # goto the first table on the page
|
139
|
+
# ie.tables.length # show how many tables are on the page. Tables that are nested will be included in this
|
140
|
+
def tables
|
141
|
+
Tables.new(self)
|
142
|
+
end
|
143
|
+
|
144
|
+
# this method accesses a table cell.
|
145
|
+
# how - symbol - how we access the cell, valid values are
|
146
|
+
# :id - find the table cell with given id.
|
147
|
+
# :xpath - find the table cell using xpath query.
|
148
|
+
#
|
149
|
+
# returns a TableCell Object
|
150
|
+
def cell(how, what=nil)
|
151
|
+
TableCell.new(self, how, what)
|
152
|
+
end
|
153
|
+
def cells
|
154
|
+
TableCells.new(self)
|
155
|
+
end
|
156
|
+
|
157
|
+
# this method accesses a table row.
|
158
|
+
# how - symbol - how we access the row, valid values are
|
159
|
+
# :id - find the table row with given id.
|
160
|
+
# :xpath - find the table row using xpath query.
|
161
|
+
#
|
162
|
+
# returns a TableRow object
|
163
|
+
def row(how, what=nil)
|
164
|
+
TableRow.new(self, how, what)
|
165
|
+
end
|
166
|
+
def rows
|
167
|
+
TableRows.new(self)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Access a modal web dialog, which is a PageContainer, like IE or Frame.
|
171
|
+
# Returns a ModalDialog object.
|
172
|
+
#
|
173
|
+
# Typical Usage
|
174
|
+
# ie.modal_dialog # access the modal dialog of ie
|
175
|
+
# ie.modal_dialog(:title, 'Title') # access the modal dialog by title
|
176
|
+
# ie.modal_dialog.modal_dialog # access a modal dialog's modal dialog XXX untested!
|
177
|
+
#
|
178
|
+
# This method will not work when
|
179
|
+
# Watir/Ruby is run under a service (instead of a user).
|
180
|
+
# Note: unlike Watir.attach, this returns before the page is assured to have
|
181
|
+
# loaded.
|
182
|
+
|
183
|
+
def modal_dialog(how=nil, what=nil)
|
184
|
+
ModalDialog.new(self, how, what)
|
185
|
+
end
|
186
|
+
|
187
|
+
# This is the main method for accessing a button. Often declared as an <input type = submit> tag.
|
188
|
+
# * how - symbol - how we access the button, :index, :id, :name etc
|
189
|
+
# * what - string, integer or regular expression - what we are looking for,
|
190
|
+
#
|
191
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
192
|
+
#
|
193
|
+
# Returns a Button object.
|
194
|
+
#
|
195
|
+
# Typical usage
|
196
|
+
#
|
197
|
+
# ie.button(:id, 'b_1') # access the button with an ID of b_1
|
198
|
+
# ie.button(:name, 'verify_data') # access the button with a name of verify_data
|
199
|
+
# ie.button(:value, 'Login') # access the button with a value (the text displayed on the button) of Login
|
200
|
+
# ie.button(:caption, 'Login') # same as above
|
201
|
+
# ie.button(:value, /Log/) # access the button that has text matching /Log/
|
202
|
+
# ie.button(:index, 2) # access the second button on the page (1 based, so the first button is accessed with :index,1)
|
203
|
+
# ie.button(:class, 'my_custom_button_class') # access the button with a class of my_custom_button_class
|
204
|
+
# ie.button(:xpath, "//input[@value='Click Me']/") # access the button with a value of Click Me
|
205
|
+
#
|
206
|
+
# Accessing a Button nested within another element
|
207
|
+
# ie.div(:class, 'xyz').button(:index, 2) # access a div of class xyz, and the 2nd button within that div
|
208
|
+
#
|
209
|
+
# If only a single parameter is supplied, then :value is used
|
210
|
+
# ie.button('Click Me') # access the button with a value of Click Me
|
211
|
+
def button(how, what=nil)
|
212
|
+
how, what = process_default :value, how, what
|
213
|
+
Button.new(self, how, what)
|
214
|
+
end
|
215
|
+
|
216
|
+
# this is the main method for accessing the buttons iterator. It returns a Buttons object
|
217
|
+
#
|
218
|
+
# Typical usage:
|
219
|
+
#
|
220
|
+
# ie.buttons.each { |b| puts b.to_s } # iterate through all the buttons on the page
|
221
|
+
# ie.buttons[1].to_s # goto the first button on the page
|
222
|
+
# ie.buttons.length # show how many buttons are on the page.
|
223
|
+
def buttons
|
224
|
+
Buttons.new(self)
|
225
|
+
end
|
226
|
+
|
227
|
+
# This is the main method for accessing a file field. Usually an <input type = file> HTML tag.
|
228
|
+
# * how - symbol - how we access the field, valid values are
|
229
|
+
# :index - find the file field using index
|
230
|
+
# :id - find the file field using id attribute
|
231
|
+
# :name - find the file field using name attribute
|
232
|
+
# :xpath - find the file field using xpath query
|
233
|
+
# * what - string, integer, regular expression, or xpath query - what we are looking for,
|
234
|
+
#
|
235
|
+
# returns a FileField object
|
236
|
+
#
|
237
|
+
# Typical Usage
|
238
|
+
#
|
239
|
+
# ie.file_field(:id, 'up_1') # access the file upload field with an ID of up_1
|
240
|
+
# ie.file_field(:name, 'upload') # access the file upload field with a name of upload
|
241
|
+
# ie.file_field(:index, 2) # access the second file upload on the page (1 based, so the first field is accessed with :index,1)
|
242
|
+
#
|
243
|
+
def file_field(how, what=nil)
|
244
|
+
FileField.new(self, how, what)
|
245
|
+
end
|
246
|
+
|
247
|
+
# this is the main method for accessing the file_fields iterator. It returns a FileFields object
|
248
|
+
#
|
249
|
+
# Typical usage:
|
250
|
+
#
|
251
|
+
# ie.file_fields.each { |f| puts f.to_s } # iterate through all the file fields on the page
|
252
|
+
# ie.file_fields[1].to_s # goto the first file field on the page
|
253
|
+
# ie.file_fields.length # show how many file fields are on the page.
|
254
|
+
def file_fields
|
255
|
+
FileFields.new(self)
|
256
|
+
end
|
257
|
+
|
258
|
+
# This is the main method for accessing a text field. Usually an <input type = text> HTML tag. or a text area - a <textarea> tag
|
259
|
+
# * how - symbol - how we access the field, :index, :id, :name etc
|
260
|
+
# * what - string, integer or regular expression - what we are looking for,
|
261
|
+
#
|
262
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
263
|
+
#
|
264
|
+
# returns a TextField object
|
265
|
+
#
|
266
|
+
# Typical Usage
|
267
|
+
#
|
268
|
+
# ie.text_field(:id, 'user_name') # access the text field with an ID of user_name
|
269
|
+
# ie.text_field(:name, 'address') # access the text field with a name of address
|
270
|
+
# ie.text_field(:index, 2) # access the second text field on the page (1 based, so the first field is accessed with :index,1)
|
271
|
+
# ie.text_field(:xpath, "//textarea[@id='user_name']/") # access the text field with an ID of user_name
|
272
|
+
def text_field(how, what=nil)
|
273
|
+
TextField.new(self, how, what)
|
274
|
+
end
|
275
|
+
|
276
|
+
# this is the method for accessing the text_fields iterator. It returns a Text_Fields object
|
277
|
+
#
|
278
|
+
# Typical usage:
|
279
|
+
#
|
280
|
+
# ie.text_fields.each { |t| puts t.to_s } # iterate through all the text fields on the page
|
281
|
+
# ie.text_fields[1].to_s # goto the first text field on the page
|
282
|
+
# ie.text_fields.length # show how many text field are on the page.
|
283
|
+
def text_fields
|
284
|
+
TextFields.new(self)
|
285
|
+
end
|
286
|
+
|
287
|
+
# This is the main method for accessing a hidden field. Usually an <input type = hidden> HTML tag
|
288
|
+
#
|
289
|
+
# * how - symbol - how we access the hidden field, :index, :id, :name etc
|
290
|
+
# * what - string, integer or regular expression - what we are looking for,
|
291
|
+
#
|
292
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
293
|
+
#
|
294
|
+
# returns a Hidden object
|
295
|
+
#
|
296
|
+
# Typical usage
|
297
|
+
#
|
298
|
+
# ie.hidden(:id, 'session_id') # access the hidden field with an ID of session_id
|
299
|
+
# ie.hidden(:name, 'temp_value') # access the hidden field with a name of temp_value
|
300
|
+
# ie.hidden(:index, 2) # access the second hidden field on the page (1 based, so the first field is accessed with :index,1)
|
301
|
+
# ie.hidden(:xpath, "//input[@type='hidden' and @id='session_value']/") # access the hidden field with an ID of session_id
|
302
|
+
def hidden(how, what=nil)
|
303
|
+
Hidden.new(self, how, what)
|
304
|
+
end
|
305
|
+
|
306
|
+
# this is the method for accessing the hiddens iterator. It returns a Hiddens object
|
307
|
+
#
|
308
|
+
# Typical usage:
|
309
|
+
#
|
310
|
+
# ie.hiddens.each { |t| puts t.to_s } # iterate through all the hidden fields on the page
|
311
|
+
# ie.hiddens[1].to_s # goto the first hidden field on the page
|
312
|
+
# ie.hiddens.length # show how many hidden fields are on the page.
|
313
|
+
def hiddens
|
314
|
+
Hiddens.new(self)
|
315
|
+
end
|
316
|
+
|
317
|
+
# This is the main method for accessing a selection list. Usually a <select> HTML tag.
|
318
|
+
# * how - symbol - how we access the selection list, :index, :id, :name etc
|
319
|
+
# * what - string, integer or regular expression - what we are looking for,
|
320
|
+
#
|
321
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
322
|
+
#
|
323
|
+
# returns a SelectList object
|
324
|
+
#
|
325
|
+
# Typical usage
|
326
|
+
#
|
327
|
+
# ie.select_list(:id, 'currency') # access the select box with an id of currency
|
328
|
+
# ie.select_list(:name, 'country') # access the select box with a name of country
|
329
|
+
# ie.select_list(:name, /n_/) # access the first select box whose name matches n_
|
330
|
+
# ie.select_list(:index, 2) # access the second select box on the page (1 based, so the first field is accessed with :index,1)
|
331
|
+
# ie.select(:xpath, "//select[@id='currency']/") # access the select box with an id of currency
|
332
|
+
def select_list(how, what)
|
333
|
+
SelectList.new(self, how, what)
|
334
|
+
end
|
335
|
+
|
336
|
+
# this is the method for accessing the select lists iterator. Returns a SelectLists object
|
337
|
+
#
|
338
|
+
# Typical usage:
|
339
|
+
#
|
340
|
+
# ie.select_lists.each { |s| puts s.to_s } # iterate through all the select boxes on the page
|
341
|
+
# ie.select_lists[1].to_s # goto the first select boxes on the page
|
342
|
+
# ie.select_lists.length # show how many select boxes are on the page.
|
343
|
+
def select_lists
|
344
|
+
SelectLists.new(self)
|
345
|
+
end
|
346
|
+
|
347
|
+
# This is the main method for accessing a check box. Usually an <input type = checkbox> HTML tag.
|
348
|
+
#
|
349
|
+
# * how - symbol - how we access the check box - :index, :id, :name etc
|
350
|
+
# * what - string, integer or regular expression - what we are looking for,
|
351
|
+
# * value - string - when there are multiple objects with different value attributes, this can be used to find the correct object
|
352
|
+
#
|
353
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
354
|
+
#
|
355
|
+
# returns a CheckBox object
|
356
|
+
#
|
357
|
+
# Typical usage
|
358
|
+
#
|
359
|
+
# ie.checkbox(:id, 'send_email') # access the check box with an id of send_mail
|
360
|
+
# ie.checkbox(:name, 'send_copy') # access the check box with a name of send_copy
|
361
|
+
# ie.checkbox(:name, /n_/) # access the first check box whose name matches n_
|
362
|
+
# ie.checkbox(:index, 2) # access the second check box on the page (1 based, so the first field is accessed with :index,1)
|
363
|
+
#
|
364
|
+
# In many instances, checkboxes on an html page have the same name, but are identified by different values. An example is shown next.
|
365
|
+
#
|
366
|
+
# <input type = checkbox name = email_frequency value = 'daily' > Daily Email
|
367
|
+
# <input type = checkbox name = email_frequency value = 'Weekly'> Weekly Email
|
368
|
+
# <input type = checkbox name = email_frequency value = 'monthly'>Monthly Email
|
369
|
+
#
|
370
|
+
# Watir can access these using the following:
|
371
|
+
#
|
372
|
+
# ie.checkbox(:id, 'day_to_send', 'monday') # access the check box with an id of day_to_send and a value of monday
|
373
|
+
# ie.checkbox(:name,'email_frequency', 'weekly') # access the check box with a name of email_frequency and a value of 'weekly'
|
374
|
+
# ie.checkbox(:xpath, "//input[@name='email_frequency' and @value='daily']/") # access the checkbox with a name of email_frequency and a value of 'daily'
|
375
|
+
def checkbox(how, what, value=nil)
|
376
|
+
CheckBox.new(self, how, what, ["checkbox"], value)
|
377
|
+
end
|
378
|
+
|
379
|
+
# this is the method for accessing the check boxes iterator. Returns a CheckBoxes object
|
380
|
+
#
|
381
|
+
# Typical usage:
|
382
|
+
#
|
383
|
+
# ie.checkboxes.each { |c| puts c.to_s } # iterate through all the check boxes on the page
|
384
|
+
# ie.checkboxes[1].to_s # goto the first check box on the page
|
385
|
+
# ie.checkboxes.length # show how many check boxes are on the page.
|
386
|
+
def checkboxes
|
387
|
+
CheckBoxes.new(self)
|
388
|
+
end
|
389
|
+
|
390
|
+
# This is the main method for accessing a radio button. Usually an <input type = radio> HTML tag.
|
391
|
+
# * how - symbol - how we access the radio button, :index, :id, :name etc
|
392
|
+
# * what - string, integer or regular expression - what we are looking for,
|
393
|
+
# * value - string - when there are multiple objects with different value attributes, this can be used to find the correct object
|
394
|
+
#
|
395
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
396
|
+
#
|
397
|
+
# returns a Radio object
|
398
|
+
#
|
399
|
+
# Typical usage
|
400
|
+
#
|
401
|
+
# ie.radio(:id, 'send_email') # access the radio button with an id of currency
|
402
|
+
# ie.radio(:name, 'send_copy') # access the radio button with a name of country
|
403
|
+
# ie.radio(:name, /n_/) # access the first radio button whose name matches n_
|
404
|
+
# ie.radio(:index, 2) # access the second radio button on the page (1 based, so the first field is accessed with :index,1)
|
405
|
+
#
|
406
|
+
# In many instances, radio buttons on an html page have the same name, but are identified by different values. An example is shown next.
|
407
|
+
#
|
408
|
+
# <input type="radio" name="email_frequency" value="daily">Daily Email</input>
|
409
|
+
# <input type="radio" name="email_frequency" value="weekly">Weekly Email</input>
|
410
|
+
# <input type="radio" name="email_frequency" value="monthly">Monthly Email</input>
|
411
|
+
#
|
412
|
+
# Watir can access these using the following:
|
413
|
+
#
|
414
|
+
# ie.radio(:id, 'day_to_send', 'monday') # access the radio button with an id of day_to_send and a value of monday
|
415
|
+
# ie.radio(:name,'email_frequency', 'weekly') # access the radio button with a name of email_frequency and a value of 'weekly'
|
416
|
+
# 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'
|
417
|
+
def radio(how, what, value=nil)
|
418
|
+
Radio.new(self, how, what, ["radio"], value)
|
419
|
+
end
|
420
|
+
|
421
|
+
# This is the method for accessing the radio buttons iterator. Returns a Radios object
|
422
|
+
#
|
423
|
+
# Typical usage:
|
424
|
+
#
|
425
|
+
# ie.radios.each { |r| puts r.to_s } # iterate through all the radio buttons on the page
|
426
|
+
# ie.radios[1].to_s # goto the first radio button on the page
|
427
|
+
# ie.radios.length # show how many radio buttons are on the page.
|
428
|
+
#
|
429
|
+
def radios
|
430
|
+
Radios.new(self)
|
431
|
+
end
|
432
|
+
|
433
|
+
# This is the main method for accessing a link.
|
434
|
+
# * how - symbol - how we access the link, :index, :id, :name, :title, :text, :url
|
435
|
+
# * what - string, integer or regular expression - what we are looking for,
|
436
|
+
#
|
437
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
438
|
+
#
|
439
|
+
# returns a Link object
|
440
|
+
#
|
441
|
+
# Typical Usage
|
442
|
+
#
|
443
|
+
# ie.link(:url, /login/) # access the first link whose url matches login. We can use a string in place of the regular expression
|
444
|
+
# # but the complete path must be used, ie.link(:url, 'http://myserver.com/my_path/login.asp')
|
445
|
+
# ie.link(:index,2) # access the second link on the page
|
446
|
+
# ie.link(:title, "Picture") # access a link using the tool tip
|
447
|
+
# ie.link(:text, 'Click Me') # access the link that has Click Me as its text
|
448
|
+
# ie.link(:xpath, "//a[contains(.,'Click Me')]/") # access the link with Click Me as its text
|
449
|
+
def link(how, what=nil)
|
450
|
+
Link.new(self, how, what)
|
451
|
+
end
|
452
|
+
|
453
|
+
# This is the main method for accessing the links collection. Returns a Links object
|
454
|
+
#
|
455
|
+
# Typical usage:
|
456
|
+
#
|
457
|
+
# ie.links.each { |l| puts l.to_s } # iterate through all the links on the page
|
458
|
+
# ie.links[1].to_s # goto the first link on the page
|
459
|
+
# ie.links.length # show how many links are on the page.
|
460
|
+
#
|
461
|
+
def links
|
462
|
+
Links.new(self)
|
463
|
+
end
|
464
|
+
|
465
|
+
# This is the main method for accessing li tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/map.asp?frame=true
|
466
|
+
# * how - symbol - how we access the li,
|
467
|
+
# * what - string, integer or regular expression - what we are looking for,
|
468
|
+
#
|
469
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
470
|
+
#
|
471
|
+
# returns a li object
|
472
|
+
#
|
473
|
+
# Typical Usage
|
474
|
+
#
|
475
|
+
# ie.li(:id, /list/) # access the first li that matches list.
|
476
|
+
# ie.li(:index,2) # access the second li on the page
|
477
|
+
# 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
|
478
|
+
#
|
479
|
+
def li(how, what)
|
480
|
+
return Li.new(self, how, what)
|
481
|
+
end
|
482
|
+
|
483
|
+
# this is the main method for accessing the lis iterator.
|
484
|
+
#
|
485
|
+
# Returns a lis object
|
486
|
+
#
|
487
|
+
# Typical usage:
|
488
|
+
#
|
489
|
+
# ie.lis.each { |s| puts s.to_s } # iterate through all the lis on the page
|
490
|
+
# ie.lis[1].to_s # goto the first li on the page
|
491
|
+
# ie.lis.length # show how many lis are on the page.
|
492
|
+
#
|
493
|
+
def lis
|
494
|
+
return Lis.new(self)
|
495
|
+
end
|
496
|
+
|
497
|
+
|
498
|
+
# This is the main method for accessing map tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/map.asp?frame=true
|
499
|
+
# * how - symbol - how we access the map,
|
500
|
+
# * what - string, integer or regular expression - what we are looking for,
|
501
|
+
#
|
502
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
503
|
+
#
|
504
|
+
# returns a map object
|
505
|
+
#
|
506
|
+
# Typical Usage
|
507
|
+
#
|
508
|
+
# ie.map(:id, /list/) # access the first map that matches list.
|
509
|
+
# ie.map(:index,2) # access the second map on the page
|
510
|
+
# 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
|
511
|
+
#
|
512
|
+
def map(how, what)
|
513
|
+
return Map.new(self, how, what)
|
514
|
+
end
|
515
|
+
|
516
|
+
# this is the main method for accessing the maps iterator.
|
517
|
+
#
|
518
|
+
# Returns a maps object
|
519
|
+
#
|
520
|
+
# Typical usage:
|
521
|
+
#
|
522
|
+
# ie.maps.each { |s| puts s.to_s } # iterate through all the maps on the page
|
523
|
+
# ie.maps[1].to_s # goto the first map on the page
|
524
|
+
# ie.maps.length # show how many maps are on the page.
|
525
|
+
#
|
526
|
+
def maps
|
527
|
+
return Maps.new(self)
|
528
|
+
end
|
529
|
+
|
530
|
+
# This is the main method for accessing area tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/area.asp?frame=true
|
531
|
+
# * how - symbol - how we access the area
|
532
|
+
# * what - string, integer or regular expression - what we are looking for,
|
533
|
+
#
|
534
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
535
|
+
#
|
536
|
+
# returns a area object
|
537
|
+
#
|
538
|
+
# Typical Usage
|
539
|
+
#
|
540
|
+
# ie.area(:id, /list/) # access the first area that matches list.
|
541
|
+
# ie.area(:index,2) # access the second area on the page
|
542
|
+
# 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
|
543
|
+
#
|
544
|
+
def area(how, what)
|
545
|
+
return Area.new(self, how, what)
|
546
|
+
end
|
547
|
+
|
548
|
+
# this is the main method for accessing the areas iterator.
|
549
|
+
#
|
550
|
+
# Returns a areas object
|
551
|
+
#
|
552
|
+
# Typical usage:
|
553
|
+
#
|
554
|
+
# ie.areas.each { |s| puts s.to_s } # iterate through all the areas on the page
|
555
|
+
# ie.areas[1].to_s # goto the first area on the page
|
556
|
+
# ie.areas.length # show how many areas are on the page.
|
557
|
+
#
|
558
|
+
def areas
|
559
|
+
return Areas.new(self)
|
560
|
+
end
|
561
|
+
|
562
|
+
# This is the main method for accessing images - normally an <img src="image.gif"> HTML tag.
|
563
|
+
# * how - symbol - how we access the image, :index, :id, :name, :src, :title or :alt are supported
|
564
|
+
# * what - string, integer or regular expression - what we are looking for,
|
565
|
+
#
|
566
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
567
|
+
#
|
568
|
+
# returns an Image object
|
569
|
+
#
|
570
|
+
# Typical Usage
|
571
|
+
#
|
572
|
+
# ie.image(:src, /myPic/) # access the first image that matches myPic. We can use a string in place of the regular expression
|
573
|
+
# # but the complete path must be used, ie.image(:src, 'http://myserver.com/my_path/my_image.jpg')
|
574
|
+
# ie.image(:index,2) # access the second image on the page
|
575
|
+
# ie.image(:alt, "A Picture") # access an image using the alt text
|
576
|
+
# ie.image(:xpath, "//img[@alt='A Picture']/") # access an image using the alt text
|
577
|
+
#
|
578
|
+
def image(how,what=nil)
|
579
|
+
Image.new(self, how, what)
|
580
|
+
end
|
581
|
+
|
582
|
+
# This is the main method for accessing the images collection. Returns an Images object
|
583
|
+
#
|
584
|
+
# Typical usage:
|
585
|
+
#
|
586
|
+
# ie.images.each { |i| puts i.to_s } # iterate through all the images on the page
|
587
|
+
# ie.images[1].to_s # goto the first image on the page
|
588
|
+
# ie.images.length # show how many images are on the page.
|
589
|
+
#
|
590
|
+
def images
|
591
|
+
Images.new(self)
|
592
|
+
end
|
593
|
+
|
594
|
+
# This is the main method for accessing JavaScript popups.
|
595
|
+
# returns a PopUp object
|
596
|
+
def popup # BUG this should not be on the container object!
|
597
|
+
PopUp.new(self)
|
598
|
+
end
|
599
|
+
|
600
|
+
# This is the main method for accessing divs. http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/div.asp?frame=true
|
601
|
+
# * how - symbol - how we access the div
|
602
|
+
# * what - string, integer, regular expression or xpath query - what we are looking for,
|
603
|
+
#
|
604
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
605
|
+
#
|
606
|
+
# returns an Div object
|
607
|
+
#
|
608
|
+
# Typical Usage
|
609
|
+
#
|
610
|
+
# ie.div(:id, /list/) # access the first div that matches list.
|
611
|
+
# ie.div(:index,2) # access the second div on the page
|
612
|
+
# ie.div(:title, "A Picture") # access a div using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
|
613
|
+
# ie.div(:xpath, "//div[@id='list']/") # access the first div whose id is 'list'
|
614
|
+
#
|
615
|
+
def div(how, what=nil)
|
616
|
+
Div.new(self, how, what)
|
617
|
+
end
|
618
|
+
|
619
|
+
# this is the main method for accessing the divs iterator. Returns a Divs collection
|
620
|
+
#
|
621
|
+
# Typical usage:
|
622
|
+
#
|
623
|
+
# ie.divs.each { |d| puts d.to_s } # iterate through all the divs on the page
|
624
|
+
# ie.divs[1].to_s # goto the first div on the page
|
625
|
+
# ie.divs.length # show how many divs are on the page.
|
626
|
+
#
|
627
|
+
def divs
|
628
|
+
Divs.new(self)
|
629
|
+
end
|
630
|
+
|
631
|
+
# This is the main method for accessing span tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/span.asp?frame=true
|
632
|
+
# * how - symbol - how we access the span,
|
633
|
+
# * what - string, integer or regular expression - what we are looking for,
|
634
|
+
#
|
635
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
636
|
+
#
|
637
|
+
# returns a Span object
|
638
|
+
#
|
639
|
+
# Typical Usage
|
640
|
+
#
|
641
|
+
# ie.span(:id, /list/) # access the first span that matches list.
|
642
|
+
# ie.span(:index,2) # access the second span on the page
|
643
|
+
# ie.span(:title, "A Picture") # access a span using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
|
644
|
+
#
|
645
|
+
def span(how, what=nil)
|
646
|
+
Span.new(self, how, what)
|
647
|
+
end
|
648
|
+
|
649
|
+
# this is the main method for accessing the spans iterator.
|
650
|
+
#
|
651
|
+
# Returns a Spans object
|
652
|
+
#
|
653
|
+
# Typical usage:
|
654
|
+
#
|
655
|
+
# ie.spans.each { |s| puts s.to_s } # iterate through all the spans on the page
|
656
|
+
# ie.spans[1].to_s # goto the first span on the page
|
657
|
+
# ie.spans.length # show how many spans are on the page.
|
658
|
+
#
|
659
|
+
def spans
|
660
|
+
Spans.new(self)
|
661
|
+
end
|
662
|
+
|
663
|
+
# This is the main method for accessing p tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/p.asp?frame=true
|
664
|
+
# * how - symbol - how we access the p,
|
665
|
+
# * what - string, integer or regular expression - what we are looking for,
|
666
|
+
#
|
667
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
668
|
+
#
|
669
|
+
# returns a P object
|
670
|
+
#
|
671
|
+
# Typical Usage
|
672
|
+
#
|
673
|
+
# ie.p(:id, /list/) # access the first p tag that matches list.
|
674
|
+
# ie.p(:index,2) # access the second p tag on the page
|
675
|
+
# ie.p(:title, "A Picture") # access a p tag using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
|
676
|
+
#
|
677
|
+
def p(how, what=nil)
|
678
|
+
P.new(self, how, what)
|
679
|
+
end
|
680
|
+
|
681
|
+
# this is the main method for accessing the ps iterator.
|
682
|
+
#
|
683
|
+
# Returns a Ps object
|
684
|
+
#
|
685
|
+
# Typical usage:
|
686
|
+
#
|
687
|
+
# ie.ps.each { |p| puts p.to_s } # iterate through all the p tags on the page
|
688
|
+
# ie.ps[1].to_s # goto the first p tag on the page
|
689
|
+
# ie.ps.length # show how many p tags are on the page.
|
690
|
+
#
|
691
|
+
def ps
|
692
|
+
Ps.new(self)
|
693
|
+
end
|
694
|
+
|
695
|
+
# This is the main method for accessing pre tags - http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/pre.asp?frame=true
|
696
|
+
# * how - symbol - how we access the pre, valid values are
|
697
|
+
# :index - finds the item using its index
|
698
|
+
# :id - finds the item using its id attribute
|
699
|
+
# :name - finds the item using its name attribute
|
700
|
+
# * what - string, integer or re, what we are looking for,
|
701
|
+
#
|
702
|
+
# returns a Pre object
|
703
|
+
#
|
704
|
+
# Typical Usage
|
705
|
+
#
|
706
|
+
# ie.pre(:id, /list/) # access the first pre tag that matches list.
|
707
|
+
# ie.pre(:index,2) # access the second pre tag on the page
|
708
|
+
# ie.pre(:title, "A Picture") # access a pre tag using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
|
709
|
+
#
|
710
|
+
def pre(how, what=nil)
|
711
|
+
Pre.new(self, how, what)
|
712
|
+
end
|
713
|
+
|
714
|
+
# this is the main method for accessing the ps iterator.
|
715
|
+
#
|
716
|
+
# Returns a Pres object
|
717
|
+
#
|
718
|
+
# Typical usage:
|
719
|
+
#
|
720
|
+
# ie.pres.each { |pre| puts pre.to_s } # iterate through all the pre tags on the page
|
721
|
+
# ie.pres[1].to_s # goto the first pre tag on the page
|
722
|
+
# ie.pres.length # show how many pre tags are on the page.
|
723
|
+
#
|
724
|
+
def pres
|
725
|
+
Pres.new(self)
|
726
|
+
end
|
727
|
+
|
728
|
+
# This is the main method for accessing labels. http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/label.asp?frame=true
|
729
|
+
# * how - symbol - how we access the label,
|
730
|
+
# * what - string, integer or regular expression - what we are looking for,
|
731
|
+
#
|
732
|
+
# Valid values for 'how' are listed in the Watir Wiki - http://wiki.openqa.org/display/WTR/Methods+supported+by+Element
|
733
|
+
#
|
734
|
+
# returns a Label object
|
735
|
+
#
|
736
|
+
# Typical Usage
|
737
|
+
#
|
738
|
+
# ie.label(:id, /list/) # access the first span that matches list.
|
739
|
+
# ie.label(:index,2) # access the second label on the page
|
740
|
+
# ie.label(:for, "text_1") # access a the label that is associated with the object that has an id of text_1
|
741
|
+
#
|
742
|
+
def label(how, what=nil)
|
743
|
+
Label.new(self, how, what)
|
744
|
+
end
|
745
|
+
|
746
|
+
# this is the main method for accessing the labels iterator. It returns a Labels object
|
747
|
+
#
|
748
|
+
# Returns a Labels object
|
749
|
+
#
|
750
|
+
# Typical usage:
|
751
|
+
#
|
752
|
+
# ie.labels.each { |l| puts l.to_s } # iterate through all the labels on the page
|
753
|
+
# ie.labels[1].to_s # goto the first label on the page
|
754
|
+
# ie.labels.length # show how many labels are on the page.
|
755
|
+
#
|
756
|
+
def labels
|
757
|
+
Labels.new(self)
|
758
|
+
end
|
759
|
+
|
760
|
+
#--
|
761
|
+
#
|
762
|
+
# Searching for Page Elements
|
763
|
+
# Not for external consumption
|
764
|
+
#
|
765
|
+
#++
|
766
|
+
def ole_inner_elements
|
767
|
+
return document.body.all
|
768
|
+
end
|
769
|
+
private :ole_inner_elements
|
770
|
+
|
771
|
+
# This method shows the available objects on the current page.
|
772
|
+
# This is usually only used for debugging or writing new test scripts.
|
773
|
+
# This is a nice feature to help find out what HTML objects are on a page
|
774
|
+
# when developing a test case using Watir.
|
775
|
+
def show_all_objects
|
776
|
+
puts "-----------Objects in page -------------"
|
777
|
+
doc = document
|
778
|
+
s = ""
|
779
|
+
props = ["name", "id", "value", "alt", "src"]
|
780
|
+
doc.all.each do |n|
|
781
|
+
begin
|
782
|
+
s += n.invoke("type").to_s.ljust(16)
|
783
|
+
rescue
|
784
|
+
next
|
785
|
+
end
|
786
|
+
props.each do |prop|
|
787
|
+
begin
|
788
|
+
p = n.invoke(prop)
|
789
|
+
s += " " + "#{prop}=#{p}".to_s.ljust(18)
|
790
|
+
rescue
|
791
|
+
# this object probably doesnt have this property
|
792
|
+
end
|
793
|
+
end
|
794
|
+
s += "\n"
|
795
|
+
end
|
796
|
+
puts s
|
797
|
+
end
|
798
|
+
|
799
|
+
#
|
800
|
+
# Locator Methods
|
801
|
+
#
|
802
|
+
|
803
|
+
# Returns the specified ole object for input elements on a web page.
|
804
|
+
#
|
805
|
+
# 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
|
806
|
+
#
|
807
|
+
# * how - symbol - the way we look for the object. Supported values are
|
808
|
+
# - :name
|
809
|
+
# - :id
|
810
|
+
# - :index
|
811
|
+
# - :value etc
|
812
|
+
# * what - string that we are looking for, ex. the name, or id tag attribute or index of the object we are looking for.
|
813
|
+
# * types - what object types we will look at.
|
814
|
+
# * value - used for objects that have one name, but many values. ex. radio lists and checkboxes
|
815
|
+
def locate_input_element(how, what, types, value=nil)
|
816
|
+
elements = nil
|
817
|
+
# Searching through all elements returned by ole_inner_elements
|
818
|
+
# is *significantly* slower than IE's getElementById() and
|
819
|
+
# getElementsByName() calls when how is :id or :name. However
|
820
|
+
# IE doesn't match Regexps, so first we make sure what is a String.
|
821
|
+
# In addition, IE's getElementById() will also return an element
|
822
|
+
# where the :name matches, so we will only return the results of
|
823
|
+
# getElementById() if the matching element actually HAS a matching
|
824
|
+
# :id.
|
825
|
+
begin
|
826
|
+
if what.class == String # Only use fast calls with String what.
|
827
|
+
if how == :id
|
828
|
+
element = document.getElementById(what)
|
829
|
+
# Return if our fast match really HAS a matching :id
|
830
|
+
return element if element.nil? or element.invoke('id') == what
|
831
|
+
elsif how == :name
|
832
|
+
elements = document.getElementsByName(what)
|
833
|
+
end
|
834
|
+
end
|
835
|
+
rescue
|
836
|
+
end
|
837
|
+
# Use slow methods if the faster methods didn't match
|
838
|
+
elements = ole_inner_elements if elements.nil?
|
839
|
+
|
840
|
+
how = :value if how == :caption
|
841
|
+
how = :class_name if how == :class
|
842
|
+
what = what.to_i if how == :index
|
843
|
+
value = value.to_s if value
|
844
|
+
log "getting object - how is #{how} what is #{what} types = #{types} value = #{value}"
|
845
|
+
|
846
|
+
object_index = 1
|
847
|
+
elements.each do |object|
|
848
|
+
element = Element.new(object)
|
849
|
+
if types.include?(element.type)
|
850
|
+
if how == :index
|
851
|
+
attribute = object_index
|
852
|
+
else
|
853
|
+
begin
|
854
|
+
attribute = element.send(how)
|
855
|
+
rescue NoMethodError
|
856
|
+
raise MissingWayOfFindingObjectException,
|
857
|
+
"#{how} is an unknown way of finding an <INPUT> element (#{what})"
|
858
|
+
end
|
859
|
+
end
|
860
|
+
if what.matches(attribute)
|
861
|
+
if value
|
862
|
+
if element.value == value
|
863
|
+
return object
|
864
|
+
end
|
865
|
+
else
|
866
|
+
return object
|
867
|
+
end
|
868
|
+
end
|
869
|
+
object_index += 1
|
870
|
+
end
|
871
|
+
end
|
872
|
+
return nil
|
873
|
+
end
|
874
|
+
|
875
|
+
# returns the ole object for the specified element
|
876
|
+
def locate_tagged_element(tag, how, what)
|
877
|
+
locator = TaggedElementLocator.new(self, tag)
|
878
|
+
locator.set_specifier(how, what)
|
879
|
+
locator.locate
|
880
|
+
end
|
881
|
+
|
882
|
+
end # module
|
883
|
+
end
|