Permalink
Browse files

make Table#hashes work

  • Loading branch information...
1 parent 983b4a6 commit 5b15966e5f8759adbc6b238a7ccc4d146905e6d3 @jarmo jarmo committed Jan 6, 2012
Showing with 29 additions and 9 deletions.
  1. +1 −1 watir/lib/watir/locator.rb
  2. +28 −8 watir/lib/watir/table.rb
@@ -75,7 +75,7 @@ def locate_elements_by_xpath_css_ole
elsif @specifiers[:css]
els = @container.send(:elements_by_css, @specifiers[:css])
elsif @specifiers[:ole_object]
- els << @specifiers[:ole_object]
+ return [@specifiers[:ole_object]]
end
els.select {|element| type_matches?(element) && match_with_specifiers?(create_element element)}
View
@@ -21,14 +21,6 @@ def strings
rows_memo
end
- def hashes
- headers = cells.map(&:text)
- rows.reduce([]) do |rows_memo, row|
- rows_memo << row.cells.each_with_index.reduce({}) do |cells_memo, cell_with_index|
- cells_memo.merge headers[cell_with_index[1]] => cell_with_index[0].text
- end
- end
- end
end
# This class is used for dealing with tables.
@@ -122,6 +114,34 @@ def row_values(rownumber)
return (0..column_count(rownumber) - 1).collect {|i| self[rownumber][i].text}
end
+ 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
end
class TableSection < NonControlElement

0 comments on commit 5b15966

Please sign in to comment.