Sha256: cdcf0255eb0f40247c02a34bf64a6e8ec2ebc4978ef1967ed8a4fead809031d6

Contents?: true

Size: 1.12 KB

Versions: 19

Compression:

Stored size: 1.12 KB

Contents

module Watir
  module Locators
    class Anchor
      class SelectorBuilder < Element::SelectorBuilder
        private

        def build_wd_selector(selector)
          build_link_text(selector) || build_partial_link_text(selector) || super
        end

        def build_link_text(selector)
          return unless can_convert_to_link_text?(selector)

          selector.delete(:tag_name)
          {link_text: selector.delete(:visible_text)}
        end

        def can_convert_to_link_text?(selector)
          selector.keys.sort == %i[tag_name visible_text] &&
            selector[:visible_text].is_a?(String)
        end

        def build_partial_link_text(selector)
          return unless convert_to_partial_link_text?(selector)

          selector.delete(:tag_name)
          {partial_link_text: selector.delete(:visible_text).source}
        end

        def convert_to_partial_link_text?(selector)
          regex = selector[:visible_text]
          selector.keys.sort == %i[tag_name visible_text] && !regex.casefold? &&
            RegexpDisassembler.new(regex).substrings.first == regex.source
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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