Class: CapybaraPageObject::TableElement
- Inherits:
-
Element
- Object
- Element
- CapybaraPageObject::TableElement
show all
- Includes:
- Enumerable
- Defined in:
- lib/capybara_page_object/elements/table_element.rb
Instance Attribute Summary
Attributes inherited from Element
#element, #page
Instance Method Summary
collapse
Methods inherited from Element
#attribute, #class, #enabled?, #focus, #html, #initialize, #method_missing, #native, #parent, #respond_to_missing?, #scroll_into_view, #within
Instance Method Details
#[](row_index) ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'lib/capybara_page_object/elements/table_element.rb', line 11
def [](row_index)
if row_index.kind_of?(String)
rows.find do |row|
row.columns.any? {|col| col.text.include?(row_index) }
end
else
rows[row_index]
end
end
|
#as_hashes ⇒ Object
21
22
23
24
25
|
# File 'lib/capybara_page_object/elements/table_element.rb', line 21
def as_hashes
rows[1..-1].map do |row|
Hash[.zip(row.map(&:text))]
end
end
|
#each ⇒ Object
5
6
7
8
9
|
# File 'lib/capybara_page_object/elements/table_element.rb', line 5
def each
for index in 1..self.rows.length do
yield self[index-1]
end
end
|
#first_row ⇒ Object
41
42
43
|
# File 'lib/capybara_page_object/elements/table_element.rb', line 41
def first_row
rows[0]
end
|
45
46
47
|
# File 'lib/capybara_page_object/elements/table_element.rb', line 45
def
rows[0].columns.map(&:text)
end
|
#last_row ⇒ Object
36
37
38
39
|
# File 'lib/capybara_page_object/elements/table_element.rb', line 36
def last_row
the_rows = rows
the_rows[the_rows.length - 1]
end
|
#rows ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/capybara_page_object/elements/table_element.rb', line 28
def rows
within do
all(:xpath, ".//child::tr").map do |row|
TableRowElement.new(row, page, self)
end
end
end
|