Class: FireWatir::Table
- Defined in:
- lib/firewatir/elements/table.rb
Constant Summary collapse
- TAG =
'TABLE'
Constants inherited from Element
Element::FIRST_ORDERED_NODE_TYPE, Element::NUMBER_TYPE, Element::ORDERED_NODE_ITERATOR_TYPE, Element::TO_S_SIZE
Constants included from Container
Container::DEFAULT_HIGHLIGHT_COLOR, Container::MACHINE_IP
Instance Attribute Summary collapse
-
#element_name ⇒ Object
Returns the value of attribute element_name.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Description: Get row at particular index in table.
-
#column_count ⇒ Object
Description: Get column count of first row in the table.
-
#column_values(column) ⇒ Object
Description: Get values of specified column in each row.
-
#each ⇒ Object
Desription: Iterate over each table row element.
-
#highlight(set_or_clear) ⇒ Object
Description: Override the highlight method, as if the tables rows are set to have a background color, this will override the table background color, and the normal flash method wont work.
-
#initialize(container, how, what) ⇒ Table
constructor
-
how - Attribute to identify the table element.
-
-
#locate ⇒ Object
Description: Locate the table element.
-
#row_count ⇒ Object
Description: Gets the number of rows in the table.
-
#row_values(row) ⇒ Object
Description: Get values of all the column in specified row.
-
#rows ⇒ Object
Description: Gets the array of rows in the table.
-
#to_a ⇒ Object
Description: Gets the table as a 2 dimensional array.
-
#to_s ⇒ Object
returns the properties of the object in a string raises an ObjectNotFound exception if the object cannot be found TODO: Implement to_s method for this class.
Methods inherited from Element
#assert_enabled, #assert_exists, #attribute_value, #click, #contains_text, #disabled, #document_var, #element_by_xpath, #element_type, #elements_by_xpath, #enabled?, #exists?, #fire_event, #inspect, #method_missing, #text, #visible?, #wait
Methods included from Container
#button, #cell, #checkbox, #dd, #dl, #dt, #file_field, #form, #frame, #hidden, #image, #link, #radio, #row, #select_list, #show_all_objects, #table, #text_field
Methods included from JsshSocket
#js_eval, #js_eval_method, #jssh_socket, #read_socket
Constructor Details
#initialize(container, how, what) ⇒ Table
-
how - Attribute to identify the table element.
-
what - Value of that attribute.
-
8 9 10 11 12 13 14 |
# File 'lib/firewatir/elements/table.rb', line 8 def initialize(container, how, what) @how = how @what = what @container = container @o = nil #super nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FireWatir::Element
Instance Attribute Details
#element_name ⇒ Object
Returns the value of attribute element_name.
3 4 5 |
# File 'lib/firewatir/elements/table.rb', line 3 def element_name @element_name end |
Instance Method Details
#[](key) ⇒ Object
145 146 147 148 149 |
# File 'lib/firewatir/elements/table.rb', line 145 def [](key) assert_exists arr_rows = rows return arr_rows[key - 1] end |
#column_count ⇒ Object
Description:
Get column count of first row in the table.
Output:
Number of columns in first row.
170 171 172 173 174 |
# File 'lib/firewatir/elements/table.rb', line 170 def column_count assert_exists arr_rows = rows return arr_rows[0].column_count end |
#column_values(column) ⇒ Object
Description:
Get values of specified column in each row.
Input:
Column number
Output:
Values of column (specified as input) in each row
186 187 188 189 190 191 192 193 194 |
# File 'lib/firewatir/elements/table.rb', line 186 def column_values(column) assert_exists arr_rows = rows values = Array.new(arr_rows.length) for i in 0..arr_rows.length - 1 do values[i] = arr_rows[i][column].to_s end return values end |
#each ⇒ Object
Desription:
Iterate over each table row element.
155 156 157 158 159 160 161 |
# File 'lib/firewatir/elements/table.rb', line 155 def each assert_exists arr_rows = rows for i in 0..arr_rows.length - 1 do yield arr_rows[i] end end |
#highlight(set_or_clear) ⇒ Object
Description:
Override the highlight method, as if the tables rows are set to have a background color,
this will override the table background color, and the normal flash method wont work
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/firewatir/elements/table.rb', line 37 def highlight(set_or_clear ) if set_or_clear == :set begin @original_border = @o.border.to_i if @o.border.to_i==1 @o.border = 2 else @o.border=1 end rescue @original_border = nil end else begin @o.border= @original_border unless @original_border == nil @original_border = nil rescue # we could be here for a number of reasons... ensure @original_border = nil end end super end |
#locate ⇒ Object
Description:
Locate the table element.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/firewatir/elements/table.rb', line 20 def locate case @how when :jssh_name @element_name = @what when :xpath @element_name = element_by_xpath(@container, @what) else @element_name = locate_tagged_element('TABLE', @how, @what) end @o = self end |
#row_count ⇒ Object
Description:
Gets the number of rows in the table.
Output:
Number of rows.
92 93 94 95 |
# File 'lib/firewatir/elements/table.rb', line 92 def row_count assert_exists return rows.length end |
#row_values(row) ⇒ Object
Description:
Get values of all the column in specified row.
Input:
Row number.
Output:
Value of all columns present in the row.
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/firewatir/elements/table.rb', line 206 def row_values(row) assert_exists arr_rows = rows cells = arr_rows[row - 1].cells values = Array.new(cells.length) for i in 0..cells.length - 1 do values[i] = cells[i].to_s end return values end |
#rows ⇒ Object
Description:
Gets the array of rows in the table.
Output:
Array of rows.
125 126 127 128 129 130 131 132 133 |
# File 'lib/firewatir/elements/table.rb', line 125 def rows assert_exists arr_rows = get_rows table_rows = Array.new(arr_rows.length) for i in 0..arr_rows.length - 1 do table_rows[i] = TableRow.new(@container, :jssh_name, arr_rows[i]) end return table_rows end |
#to_a ⇒ Object
Description:
Gets the table as a 2 dimensional array. Dont expect too much if there are nested tables, colspan etc.
Output:
2D array with rows and column text of the table.
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/firewatir/elements/table.rb', line 104 def to_a assert_exists y = [] table_rows = rows for row in table_rows x = [] row.each do |td| x << td.to_s.strip end y << x end return y end |
#to_s ⇒ Object
returns the properties of the object in a string raises an ObjectNotFound exception if the object cannot be found TODO: Implement to_s method for this class.
79 80 81 82 83 |
# File 'lib/firewatir/elements/table.rb', line 79 def to_s assert_exists r = super({"rows" => "rows.length","columns" => "columnLength", "cellspacing" => "cellspacing", "cellpadding" => "cellpadding", "border" => "border"}) # r += self.column_count.to_s end |