Sha256: ba17e9ab9afc487124e1e9ae7ad5f64babfb725640eb4b8cea0285c44ebeed67

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module PageObject
  module Platforms
    module SeleniumWebDriver
      module Table

        #
        # Return the PageObject::Elements::TableRow for the index provided.  Index
        # is zero based.  If the index provided is a String then it
        # will be matched with the text from the first column.
        #
        # @return [PageObject::Elements::TableRow]
        #
        def [](idx)
          eles = table_rows
          idx = find_index_by_title(idx, eles) if idx.kind_of?(String)
          Object::PageObject::Elements::TableRow.new(eles[idx], :platform => :selenium_webdriver)
        end

        #
        # Returns the number of rows in the table.
        #
        def rows
          table_rows.size
        end

        #
        # override PageObject::Platforms::SeleniumElement because exists? is not
        # available on a table element in Selenium.
        #
        def exists?
          raise "exists? not available on table element"
        end

        private

        def find_index_by_title(row_title, eles)
          eles.find_index do |row|
            columns = row.find_elements(:xpath, ".//child::td|th")
            columns.first.text == row_title
          end
        end

        def table_rows
          element.find_elements(:xpath, child_xpath)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
page-object-0.6.7 lib/page-object/platforms/selenium_webdriver/table.rb