Class: Watir::TableRow
Constant Summary
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
#<=>, #activeObjectHighLightColor, #after_text, #assert_enabled, #assert_exists, #attribute_value, #before_text, #click, #click!, #document, #enabled?, #exists?, #fire_event, #flash, #focus, #inspect, #method_missing, #ole_object, #ole_object=, #parent, #text, #to_s, #type_keys, #typingspeed, #visible?
Methods included from Container
#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #element_by_css, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #hidden, #hiddens, #image, #images, #labels, #link, #links, #lis, #locate_all_elements, #locate_input_element, #locate_tagged_element, #log, #map, #maps, #modal_dialog, #popup, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #set_container, #show_all_objects, #spans, #strongs, #table, #tables, #text_field, #text_fields, #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
283 284 285 286 287 288 |
# File 'lib/watir/table.rb', line 283 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
297 298 299 300 301 302 303 |
# File 'lib/watir/table.rb', line 297 def [](index) assert_exists if @cells.length < index raise UnknownCellException, "Unable to locate a cell at index #{index}" end return @cells[(index - 1)] 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
310 311 312 313 |
# File 'lib/watir/table.rb', line 310 def column_count locate @cells.length end |
#each ⇒ Object
this method iterates through each of the cells in the row. Yields a TableCell object
291 292 293 294 |
# File 'lib/watir/table.rb', line 291 def each locate 0.upto(@cells.length-1) { |i| yield @cells[i] } end |
#locate ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/watir/table.rb', line 259 def locate @o = nil if @how == :ole_object @o = @what elsif @how == :xpath @o = @container.element_by_xpath(@what) elsif @how == :css @o = @container.element_by_css(@what) else @o = @container.locate_tagged_element("TR", @how, @what) end if @o # cant call the assert_exists here, as an exists? method call will fail @cells = [] @o.cells.each do |oo| @cells << TableCell.new(@container, :ole_object, oo) end end 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
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/watir/table.rb', line 319 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 |