Sha256: 16f498eb9825105a606d685aef2120bdf616064257efc74bf9a32d0317a308c0

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

module Watir
  module Locators
    class Row
      class SelectorBuilder
        class XPath < Element::SelectorBuilder::XPath
          def build(selector, scope_tag_name)
            return super(selector) if selector.key?(:adjacent)

            index = selector.delete(:index)

            common_string = super(selector)[:xpath]
            expressions = generate_expressions(scope_tag_name)
            expressions.map! { |e| "#{e}#{common_string}" } unless common_string.empty?

            xpath = expressions.join(' | ').to_s

            xpath = index ? add_index(xpath, index) : xpath

            @selector.merge! @requires_matches

            {xpath: xpath}
          end

          private

          def start_string
            @adjacent ? './' : ''
          end

          def text_string
            return super if @adjacent

            # Can not directly locate a Row with Text because all text is in the Cells;
            # needs to use Locator#locate_matching_elements
            @requires_matches[:text] = @selector.delete(:text) if @selector.key?(:text)
            ''
          end

          def generate_expressions(scope_tag_name)
            if %w[tbody tfoot thead].include?(scope_tag_name)
              ["./*[local-name()='tr']"]
            else
              ["./*[local-name()='tr']",
               "./*[local-name()='tbody']/*[local-name()='tr']",
               "./*[local-name()='thead']/*[local-name()='tr']",
               "./*[local-name()='tfoot']/*[local-name()='tr']"]
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
watir-6.15.0 lib/watir/locators/row/selector_builder/xpath.rb