Class: Celerity::Table
- Includes:
- ClickableElement, Container, Enumerable
- Defined in:
- lib/celerity/elements/table.rb
Constant Summary collapse
- TAGS =
[ Identifier.new('table') ]
- ATTRIBUTES =
BASE_ATTRIBUTES | [:summary, :width, :border, :frame, :rules, :cellspacing, :cellpadding, :align, :bgcolor]
- DEFAULT_HOW =
:id
Constants inherited from Element
Element::BASE_ATTRIBUTES, Element::CELLHALIGN_ATTRIBUTES, Element::CELLVALIGN_ATTRIBUTES, Element::HTML_401_TRANSITIONAL, Element::TO_S_SIZE
Instance Attribute Summary
Attributes included from Container
Attributes inherited from Element
Instance Method Summary collapse
- #cells ⇒ Celerity::TableCells
-
#child_cell(index) ⇒ Celerity::TableCell
Returns the TableCell at the given index (1-indexed).
-
#child_row(index) ⇒ Celerity::TableRow
(also: #[])
Returns the TableRow at the given index (1-indexed).
-
#column_count(index = Celerity.index_offset) ⇒ Fixnum
Returns the number of columns on the row at the given index.
- #column_values(column_number) ⇒ Object
-
#each {|row| ... } ⇒ Object
Iterates through each row in the table.
- #locate ⇒ Object
-
#row_count ⇒ Fixnum
The number of rows in the table.
- #row_values(row_number) ⇒ Object
- #rows ⇒ Celerity::TableRows
-
#to_a ⇒ Array<Array<String>>
Returns the text of each cell in the the table as a two-dimensional array.
Methods included from 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, #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 ShortInspect
Methods included from ClickableElement
#click, #click_and_attach, #double_click, #download, #right_click
Methods inherited from Element
#assert_exists, #attribute_string, #attribute_value, #exists?, #fire_event, #focus, #initialize, #javascript_object, #method_missing, #methods, #object, #parent, #respond_to?, #text, #to_s, #to_xml, #visible?, #xpath
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
Instance Method Details
#cells ⇒ Celerity::TableCells
41 42 43 44 |
# File 'lib/celerity/elements/table.rb', line 41 def cells assert_exists TableCells.new(self, :object, @cells) end |
#child_cell(index) ⇒ Celerity::TableCell
Returns the TableCell at the given index (1-indexed).
In a 10-column row, table.child_cell will return the first cell on the second row.
88 89 90 91 92 93 94 95 96 |
# File 'lib/celerity/elements/table.rb', line 88 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 |
#child_row(index) ⇒ Celerity::TableRow 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...>
67 68 69 70 71 72 73 74 75 |
# File 'lib/celerity/elements/table.rb', line 67 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 |
#column_count(index = Celerity.index_offset) ⇒ Fixnum
Returns the number of columns on the row at the given index. (1-indexed) Default is the number of columns on the first row
115 116 117 118 |
# File 'lib/celerity/elements/table.rb', line 115 def column_count(index = Celerity.index_offset) assert_exists @object.getRow(index - Celerity.index_offset).getCells.length end |
#column_values(column_number) ⇒ Object
135 136 137 |
# File 'lib/celerity/elements/table.rb', line 135 def column_values(column_number) (1..row_count).map { |index| self[index][column_number].text } end |
#each {|row| ... } ⇒ Object
Iterates through each row in the table.
51 52 53 54 |
# File 'lib/celerity/elements/table.rb', line 51 def each assert_exists @rows.each { |row| yield TableRow.new(self, :object, row) } end |
#locate ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/celerity/elements/table.rb', line 13 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 |
#row_count ⇒ Fixnum
The number of rows in the table
103 104 105 106 |
# File 'lib/celerity/elements/table.rb', line 103 def row_count assert_exists @object.getRowCount end |
#row_values(row_number) ⇒ Object
139 140 141 |
# File 'lib/celerity/elements/table.rb', line 139 def row_values(row_number) (1..column_count(row_number)).map { |index| self[row_number][index].text } end |
#rows ⇒ Celerity::TableRows
32 33 34 35 |
# File 'lib/celerity/elements/table.rb', line 32 def rows assert_exists TableRows.new(self, :object, @rows) end |
#to_a ⇒ Array<Array<String>>
Returns the text of each cell in the the table as a two-dimensional array.
125 126 127 128 129 130 131 132 133 |
# File 'lib/celerity/elements/table.rb', line 125 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 |