Class: Watir::Table

Inherits:
Element show all
Includes:
TableCellsContainer, TableContainer, TableRowsContainer
Defined in:
lib/watir-classic/table.rb

Overview

Returned by Container#table

Instance Attribute Summary

Attributes inherited from Element

#container

Attributes included from Container

#page_container

Instance Method Summary collapse

Methods included from TableCellsContainer

#cell, #cells

Methods included from TableRowsContainer

#row, #rows

Methods included from TableContainer

#[], #strings

Methods inherited from Element

#<=>, #attribute_value, #class_name, #click, #disabled?, #double_click, #enabled?, #exists?, #fire_event, #flash, #focus, #focused?, #html, #id, #initialize, #inspect, #method_missing, #ole_object, #parent, #right_click, #send_keys, #style, #tag_name, #text, #title, #to_subtype, #unique_number, #visible?

Methods included from DragAndDropHelper

#drag_and_drop_by, #drag_and_drop_on

Methods included from Container

#a, #abbr, #address, #alert, #area, #article, #aside, #audio, #b, #base, #bdi, #bdo, #blockquote, #body, #br, #button, #canvas, #caption, #checkbox, #cite, #code, #col, #colgroup, #command, #data, #datalist, #dd, #del, #details, #dfn, #div, #dl, #dt, #element, #em, #embed, #fieldset, #figcaption, #figure, #file_field, #font, #footer, #form, #frame, #frameset, #h1, #h2, #h3, #h4, #h5, #h6, #head, #header, #hgroup, #hidden, #hr, #i, #img, #input, #ins, #kbd, #keygen, #label, #legend, #li, #map, #mark, #menu, #meta, #meter, #modal_dialog, #nav, #noscript, #object, #ol, #optgroup, #option, #output, #p, #param, #pre, #progress, #q, #radio, #rp, #rt, #ruby, #s, #samp, #script, #section, #select, #small, #source, #span, #strong, #style, #sub, #summary, #sup, #table, #tbody, #td, #text_field, #textarea, #tfoot, #th, #thead, #time, #title, #tr, #track, #u, #ul, #var, #video, #wbr

Methods included from Exception

message_for_unable_to_locate

Methods included from ElementExtensions

#present?, #wait_until_present, #wait_while_present, #when_present

Constructor Details

This class inherits a constructor from Watir::Element

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Watir::Element

Instance Method Details

#column_count(index = 0) ⇒ Fixnum

Returns number of columns inside of the table, including columns from nested tables.

Parameters:

  • index (Fixnum) (defaults to: 0)

    the number of row.

Returns:

  • (Fixnum)

    number of columns inside of the table, including columns from nested tables.



97
98
99
100
# File 'lib/watir-classic/table.rb', line 97

def column_count(index=0)
  assert_exists
  rows[index].cells.length
end

#column_values(columnnumber) ⇒ Array<String>

Returns array of each row’s specified column text.

Parameters:

  • columnnumber (Fixnum)

    the number of column to extract text from.

Returns:

  • (Array<String>)

    array of each row’s specified column text.



105
106
107
# File 'lib/watir-classic/table.rb', line 105

def column_values(columnnumber)
  (0..row_count - 1).collect {|i| self[i][columnnumber].text}
end

#hashesArray<Hash>

Returns array with hashes of table data.

Returns:

  • (Array<Hash>)

    array with hashes of table data.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/watir-classic/table.rb', line 118

def hashes
  assert_exists

  headers = []
  @o.rows.item(0).cells.each do |cell|
    headers << TableCell.new(self, :ole_object => cell).text
  end

  rows_memo = []
  i = 0
  @o.rows.each do |row|
    next if row.uniqueID == @o.rows.item(0).uniqueID

    cells_memo = {}
    cells = row.cells
    raise "row at index #{i} has #{cells.length} cells, expected #{headers.length}" if cells.length < headers.length

    j = 0
    cells.each do |cell|
      cells_memo[headers[j]] = TableCell.new(self, :ole_object => cell).text
      j += 1
    end

    rows_memo << cells_memo
    i += 1
  end
  rows_memo
end

#row_countFixnum

Returns number of rows inside of the table, including rows from nested tables.

Returns:

  • (Fixnum)

    number of rows inside of the table, including rows from nested tables.



88
89
90
91
# File 'lib/watir-classic/table.rb', line 88

def row_count
  assert_exists
  rows.length
end

#row_values(rownumber) ⇒ Array<String>

Returns array of each column’s text on specified row.

Parameters:

  • rownumber (Fixnum)

    the number of row to extract column texts from.

Returns:

  • (Array<String>)

    array of each column’s text on specified row.



112
113
114
# File 'lib/watir-classic/table.rb', line 112

def row_values(rownumber)
  (0..column_count(rownumber) - 1).collect {|i| self[rownumber][i].text}
end

#to_sObject



147
148
149
150
151
152
# File 'lib/watir-classic/table.rb', line 147

def to_s
  assert_exists
  r = string_creator
  r += table_string_creator
  r.join("\n")
end