Class: Celerity::Table
- Inherits:
-
Celerity::Element
- Object
- Celerity::Element
- Celerity::Table
- Includes:
- Celerity::ClickableElement, Celerity::Container, Enumerable
- Defined in:
- lib/celerity/elements/table.rb
Overview
Table
Constant Summary
- TAGS =
[ Identifier.new('table') ]
- ATTRIBUTES =
BASE_ATTRIBUTES | [ :align, :bgcolor, :border, :cellpadding, :cellspacing, :frame, :rules, :summary, :width, ]
- DEFAULT_HOW =
:id
Constants inherited from Celerity::Element
ATTRIBUTES, BASE_ATTRIBUTES, CELLHALIGN_ATTRIBUTES, CELLVALIGN_ATTRIBUTES, DEFAULT_HOW, HTML_401_TRANSITIONAL, TAGS
Method Summary
- - (Celerity::TableCells) cells
- - (Celerity::TableCell) child_cell(index) Returns the TableCell at the given index (1-indexed).
- - (Celerity::TableRow) child_row(index) (also: #[]) Returns the TableRow at the given index (1-indexed).
- - (Fixnum) column_count(index = Celerity.index_offset) Returns the number of columns on the row at the given index.
- - (Object) column_values(column_number)
- - (Object) each {|row| ... } Iterates through each row in the table.
- - (Object) locate
- - (Fixnum) row_count The number of rows in the table.
- - (Object) row_values(row_number)
- - (Celerity::TableRows) rows
- - (Array<Array<String>>) to_a Returns the text of each cell in the the table as a two-dimensional array.
Methods included from Celerity::ClickableElement
#assert_exists_and_enabled, #click, #click_and_attach, #double_click, #download, #right_click
Methods included from Celerity::Container
#area, #areas, #button, #buttons, #cell, #check_box, #checkboxes, #container=, #contains_text, #dd, #dds, #div, #divs, #dl, #dls, #dt, #dts, #em, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #hidden, #hiddens, #image, #images, #inspect, #label, #labels, #li, #link, #links, #lis, #map, #maps, #meta, #metas, #ol, #ols, #option, #p, #pre, #pres, #ps, #radio, #radios, #rescue_status_code_exception, #row, #select_list, #select_lists, #span, #spans, #strong, #strongs, #table, #tables, #tbodies, #tbody, #text_field, #text_fields, #tfoot, #tfoots, #th, #thead, #theads, #ths, #ul, #uls
Methods included from Celerity::ShortInspect
Methods inherited from Celerity::Element
#==, #assert_exists, #attribute_string, #attribute_value, #exists?, #fire_event, #focus, #identifier_string, #initialize, #javascript_object, #method_missing, #methods, #object, #parent, #respond_to?, #selector_to_attribute, #text, #to_s, #to_xml, #visible?, #xpath
Methods included from Celerity::Container
#area, #areas, #button, #buttons, #cell, #check_box, #checkboxes, #container=, #contains_text, #dd, #dds, #div, #divs, #dl, #dls, #dt, #dts, #em, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #hidden, #hiddens, #image, #images, #inspect, #label, #labels, #li, #link, #links, #lis, #map, #maps, #meta, #metas, #ol, #ols, #option, #p, #pre, #pres, #ps, #radio, #radios, #rescue_status_code_exception, #row, #select_list, #select_lists, #span, #spans, #strong, #strongs, #table, #tables, #tbodies, #tbody, #text_field, #text_fields, #tfoot, #tfoots, #th, #thead, #theads, #ths, #ul, #uls
Methods included from Celerity::ShortInspect
Constructor Details
This class inherits a constructor from Celerity::Element
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Celerity::Element
Method Details
- (Celerity::TableCells) cells
50 51 52 53 |
# File 'lib/celerity/elements/table.rb', line 50 def cells assert_exists TableCells.new(self, :object, @cells) end |
- (Celerity::TableCell) child_cell(index)
Returns the TableCell at the given index (1-indexed).
In a 10-column row, table.child_cell[11] will return the first cell on the second row.
97 98 99 100 101 102 103 104 105 |
# File 'lib/celerity/elements/table.rb', line 97 def child_cell(index) assert_exists if (index - Celerity.index_offset) >= @cells.length raise UnknownCellException, "Unable to locate a cell at index #{index}" end TableCell.new(self, :object, @cells[index - Celerity.index_offset]) end |
- (Celerity::TableRow) child_row(index) Also known as: []
Returns the TableRow at the given index (1-indexed).
browser.table(:foo, 'bar')[1] # => #<TableRow...> browser.table(:foo, 'bar').child_row[1] # => #<TableRow...>
76 77 78 79 80 81 82 83 84 |
# File 'lib/celerity/elements/table.rb', line 76 def child_row(index) assert_exists if (index - Celerity.index_offset) >= @rows.length raise UnknownRowException, "Unable to locate a row at index #{index}" end TableRow.new(self, :object, @rows[index - Celerity.index_offset]) end |
- (Fixnum) column_count(index = Celerity.index_offset)
Returns the number of columns on the row at the given index. (1-indexed) Default is the number of columns on the first row
124 125 126 127 |
# File 'lib/celerity/elements/table.rb', line 124 def column_count(index = Celerity.index_offset) assert_exists @object.getRow(index - Celerity.index_offset).getCells.length end |
- (Object) column_values(column_number)
144 145 146 |
# File 'lib/celerity/elements/table.rb', line 144 def column_values(column_number) (1..row_count).map { |index| self[index][column_number].text } end |
- (Object) each {|row| ... }
Iterates through each row in the table.
60 61 62 63 |
# File 'lib/celerity/elements/table.rb', line 60 def each assert_exists @rows.each { |row| yield TableRow.new(self, :object, row) } end |
- (Object) locate
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/celerity/elements/table.rb', line 22 def locate super if @object # cant call assert_exists here, as an exists? method call will fail @rows = @object.getRows @cells = [] @rows.each do |row| row.getCells.each do |c| @cells << c end end end @object end |
- (Fixnum) row_count
The number of rows in the table
112 113 114 115 |
# File 'lib/celerity/elements/table.rb', line 112 def row_count assert_exists @object.getRowCount end |
- (Object) row_values(row_number)
148 149 150 |
# File 'lib/celerity/elements/table.rb', line 148 def row_values(row_number) (1..column_count(row_number)).map { |index| self[row_number][index].text } end |
- (Celerity::TableRows) rows
41 42 43 44 |
# File 'lib/celerity/elements/table.rb', line 41 def rows assert_exists TableRows.new(self, :object, @rows) end |
- (Array<Array<String>>) to_a
Returns the text of each cell in the the table as a two-dimensional array.
134 135 136 137 138 139 140 141 142 |
# File 'lib/celerity/elements/table.rb', line 134 def to_a assert_exists # @object.getRows.map do |table_row| # table_row.getCells.map { |td| td.asText.strip } # end rows.map do |table_row| table_row.map { |td| td.text } end end |