Sha256: a2de1b677682d5e1df91297991d4840482fd466ba057b7f84d83eb2a0cc02dfa

Contents?: true

Size: 1.52 KB

Versions: 18

Compression:

Stored size: 1.52 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)

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

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

            @built[:xpath] = index ? add_index(xpath, index) : xpath
            @built
          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
            @built[: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

18 entries across 18 versions & 1 rubygems

Version Path
watir-7.1.0 lib/watir/locators/row/selector_builder/xpath.rb
watir-7.0.0 lib/watir/locators/row/selector_builder/xpath.rb
watir-7.0.0.beta5 lib/watir/locators/row/selector_builder/xpath.rb
watir-7.0.0.beta4 lib/watir/locators/row/selector_builder/xpath.rb
watir-7.0.0.beta3 lib/watir/locators/row/selector_builder/xpath.rb
watir-7.0.0.beta2 lib/watir/locators/row/selector_builder/xpath.rb
watir-7.0.0.beta1 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.19.1 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.19.0 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.18.0 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.17.0 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.16.5 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.16.4 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.16.3 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.16.2 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.16.1 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.16.0 lib/watir/locators/row/selector_builder/xpath.rb
watir-6.15.1 lib/watir/locators/row/selector_builder/xpath.rb