class Watir::Table
Public Instance Methods
[](idx)
click to toggle source
Returns row of this table with given index.
@param [Integer] idx @return Watir::Row
# File lib/watir/elements/table.rb, line 57 def [](idx) row(index: idx) end
cell_size_check(header_row, cell_row)
click to toggle source
@api private
# File lib/watir/elements/table.rb, line 65 def cell_size_check(header_row, cell_row) header_size = header_row.cells.size row_size = cell_row.cells.size return if header_size == row_size index = cell_row.selector[:index] row_id = index ? "row at index #{index - 1}" : 'designated row' raise Error, "#{row_id} has #{row_size} cells, while header row has #{header_size}" end
each(&block)
click to toggle source
Yields each TableRow
associated with this table.
@example
table = browser.table table.each do |row| puts row.text end
@yieldparam [Watir::TableRow] element Iterate through the rows for this table.
# File lib/watir/elements/table.rb, line 18 def each(&block) rows.each(&block) end
hashes()
click to toggle source
Represents table rows as hashes
@return [Array<Hash>]
# File lib/watir/elements/table.rb, line 28 def hashes all_rows = rows.locate header_row = all_rows.first || raise(Error, 'no rows in table') all_rows.entries[1..-1].map do |row| cell_size_check(header_row, row) Hash[headers(header_row).map(&:text).zip(row.cells.map(&:text))] end end
headers(row = nil)
click to toggle source
Returns first row of Table
with proper subtype
@return [TableCellCollection]
# File lib/watir/elements/table.rb, line 44 def headers(row = nil) row ||= rows.first header_type = row.th.exist? ? 'th' : 'td' row.send("#{header_type}s") end