Class: Watir::Table

Inherits:
HTMLElement show all
Defined in:
lib/watir-webdriver/elements/table.rb,
lib/watir-webdriver/elements/generated.rb,
lib/watir-webdriver/elements/generated.rb

Constant Summary

Constants inherited from BaseElement

BaseElement::IGNORED_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from BaseElement

attribute_list, #attribute_value, attributes, #click, #double_click, #driver, #element, #exists?, #fire_event, #flash, #focus, #html, #initialize, #inspect, #parent, #right_click, #run_checkers, #send_keys, #style, #tag_name, #text, typed_attributes, #value, #visible?

Methods included from Container

add

Methods included from XpathSupport

#element_by_xpath, #elements_by_xpath

Constructor Details

This class inherits a constructor from Watir::BaseElement

Instance Method Details

#[](idx) ⇒ Object

Get the n’th row of this table.

Returns:

  • Watir::TableRow



25
26
27
# File 'lib/watir-webdriver/elements/table.rb', line 25

def [](idx)
  row(:index, idx)
end

#to_aArray<Array<String>>

The table as an 2D Array of strings with the text of each cell.

Returns:



11
12
13
14
15
16
17
# File 'lib/watir-webdriver/elements/table.rb', line 11

def to_a
  assert_exists

  trs.inject [] do |res, row|
    res << row.wd.find_elements(:xpath, ".//td | .//th").map { |cell| cell.text }
  end
end