Sha256: 9b1d105c42cea7a4841ead2b9b2e19d6bfc1f4e790084e6214da4a0ef496e329

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

module PageObject
  module Platforms
    module WatirWebDriver
      module TableRow

        #
        # Return the PageObject::Elements::TableCell 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 columns in the first row.
        # The text can be a substring of the full column text.
        #
        def [](idx)
          idx = find_index_by_title(idx) if idx.kind_of?(String)
          return nil unless idx && columns >= idx + 1
          initialize_cell(element[idx], :platform => @platform.class::PLATFORM_NAME)
        end

        #
        # Returns the number of columns in the table.
        #
        def columns
          element.wd.find_elements(:xpath, child_xpath).size
        end

        private

        def find_index_by_title(title)
          table = element.parent
          table = table.parent if table.tag_name == 'tbody'
          first_row = table[0]
          first_row.cells.find_index {|column| column.text.include? title }
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
page-object-2.0.0 lib/page-object/platforms/watir/table_row.rb
page-object-1.2.2 lib/page-object/platforms/watir_webdriver/table_row.rb
page-object-1.2.1 lib/page-object/platforms/watir_webdriver/table_row.rb
page-object-1.2.0 lib/page-object/platforms/watir_webdriver/table_row.rb