Sha256: e8a766b46076c81d681ed0d48b3068a48aee1810d2d22047db94c1a9a5648599

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 Bytes

Contents

module Watir
  module Locators
    class Row
      class SelectorBuilder < Element::SelectorBuilder
        def build_wd_selector(selectors)
          return if selectors.values.any? { |e| e.is_a? Regexp }

          selectors.delete(:tag_name) || raise('internal error: no tag_name?!')

          expressions = generate_expressions(@query_scope.tag_name.downcase)

          attr_expr = xpath_builder.attribute_expression(nil, selectors)

          expressions.map! { |e| "#{e}[#{attr_expr}]" } unless attr_expr.empty?

          xpath = expressions.join(' | ')

          p build_wd_selector: xpath if $DEBUG

          [:xpath, xpath]
        end

        protected

        def generate_expressions(tag_name)
          expressions = %w[./tr]
          expressions += %w[./tbody/tr ./thead/tr ./tfoot/tr] unless %w[tbody tfoot thead].include?(tag_name)
          expressions
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
watir-6.14.0 lib/watir/locators/row/selector_builder.rb