Class: Watir::TableRow
Constant Summary collapse
- TAG =
"TR"
Constants inherited from Element
Instance Attribute Summary
Attributes inherited from Element
Attributes included from Container
#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed
Instance Method Summary collapse
-
#[](index) ⇒ Object
Returns an element from the row as a TableCell object.
-
#column_count ⇒ Object
defaults all missing methods to the array of elements, to be able to use the row as an array def method_missing(aSymbol, *args) return @o.send(aSymbol, *args) end.
-
#each ⇒ Object
this method iterates through each of the cells in the row.
-
#initialize(container, how, what) ⇒ TableRow
constructor
Returns an initialized instance of a table row * o - the object contained in the row * container - an instance of an IE object * how - symbol - how we access the row * what - what we use to access the row - id, index etc.
- #locate ⇒ Object
-
#to_a(max_depth = 1) ⇒ Object
Returns (multi-dimensional) array of the cell texts in table’s row.
Methods inherited from Element
#<=>, #__ole_inner_elements, #activeObjectHighLightColor, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #create_event, #dispatch_event, #document, #enabled?, #exists?, #fire_event, #flash, #focus, inherited, #inspect, #method_missing, #name, #ole_object, #ole_object=, #parent, #text, #to_s, #type_keys, #typingspeed, #visible?
Methods included from Container
#__ole_inner_elements, #input_element_locator, #locator_for, #log, #set_container, #show_all_objects, #tagged_element_locator, #wait
Constructor Details
#initialize(container, how, what) ⇒ TableRow
Returns an initialized instance of a table row
* o - the object contained in the row
* container - an instance of an IE object
* how - symbol - how we access the row
* what - what we use to access the row - id, index etc. If how is :ole_object then what is a Internet Explorer Raw Row
270 271 272 273 274 275 |
# File 'lib/watir/table.rb', line 270 def initialize(container, how, what) set_container container @how = how @what = what super nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Watir::Element
Instance Method Details
#[](index) ⇒ Object
Returns an element from the row as a TableCell object
284 285 286 287 288 289 290 |
# File 'lib/watir/table.rb', line 284 def [](index) assert_exists if cells.length <= index raise UnknownCellException, "Unable to locate a cell at index #{index}" end return cells[index] end |
#column_count ⇒ Object
defaults all missing methods to the array of elements, to be able to use the row as an array
def method_missing(aSymbol, *args)
return @o.send(aSymbol, *args)
end
297 298 299 300 |
# File 'lib/watir/table.rb', line 297 def column_count locate cells.length end |
#each ⇒ Object
this method iterates through each of the cells in the row. Yields a TableCell object
278 279 280 281 |
# File 'lib/watir/table.rb', line 278 def each locate 0.upto(cells.length - 1) { |i| yield cells[i] } end |
#locate ⇒ Object
248 249 250 251 |
# File 'lib/watir/table.rb', line 248 def locate super cells if @o end |
#to_a(max_depth = 1) ⇒ Object
Returns (multi-dimensional) array of the cell texts in table’s row.
Works with th, td elements, colspan, rowspan and nested tables. Takes an optional parameter max_depth, which is by default 1
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/watir/table.rb', line 306 def to_a(max_depth=1) assert_exists y = [] @o.cells.each do |cell| inner_tables = cell.getElementsByTagName("TABLE") inner_tables.each do |inner_table| # make sure that the inner table is directly child for this cell if inner_table?(cell, inner_table) max_depth -= 1 y << Table.new(@container, :ole_object, inner_table).to_a(max_depth) if max_depth >= 1 end end if inner_tables.length == 0 y << cell.innerText.strip end end y end |