Sha256: 9f6ee99c0ae5e1cebafaf59faa4d152baa337cb354385cf9b72979658a419c42

Contents?: true

Size: 1.35 KB

Versions: 14

Compression:

Stored size: 1.35 KB

Contents

module Watir
  class ButtonLocator < ElementLocator

    def locate_all
      find_all_by_multiple
    end

    def build_xpath(selectors)
      return if selectors.values.any? { |e| e.kind_of? Regexp }

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

      @building = :button
      button_attr_exp = attribute_expression(selectors)

      @building = :input
      selectors[:type] = %w[button reset submit image]
      input_attr_exp = attribute_expression(selectors)

      xpath = ".//button"
      xpath << "[#{button_attr_exp}]" unless button_attr_exp.empty?
      xpath << " | .//input"
      xpath << "[#{input_attr_exp}]"

      p :build_xpath => xpath if $DEBUG

      xpath
    end

    def lhs_for(key)
      if @building == :input && key == :text
        "@value"
      elsif @building == :button && key == :value
        "text()"
      else
        super
      end
    end

    def matches_selector?(rx_selector, element)
      rx_selector = rx_selector.dup

      [:value, :caption].each do |key|
        if rx_selector.has_key?(key)
          correct_key = element.tag_name == 'button' ? :text : :value
          rx_selector[correct_key] = rx_selector.delete(key)
        end
      end

      super
    end

    def tag_name_matches?(element, _)
      !!(/^(input|button)$/ === element.tag_name)
    end
  end # ButtonLocator
end # Watir

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
watir-webdriver-0.0.7 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.6 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.5 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.4 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.3 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.2 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.1 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.1.dev7 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.1.dev6 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.1.dev5 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.1.dev4 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.1.dev3 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.1.dev2 lib/watir-webdriver/locators/button_locator.rb
watir-webdriver-0.0.1.dev lib/watir-webdriver/locators/button_locator.rb