Sha256: 79c6eb0c473599c5735cb20ec68f4a689911ce619749ac11a0d833c33b4f5375

Contents?: true

Size: 1.34 KB

Versions: 49

Compression:

Stored size: 1.34 KB

Contents

require "webrat/core/locators/locator"

module Webrat
  module Locators

    class ButtonLocator < Locator # :nodoc:

      def locate
        ButtonField.load(@session, button_element)
      end

      def button_element
        button_elements.detect do |element|
          @value.nil?             ||
          matches_id?(element)    ||
          matches_value?(element) ||
          matches_html?(element)  ||
          matches_alt?(element)
        end
      end

      def matches_id?(element)
        (@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") =~ @value) ||
        (!@value.is_a?(Regexp) && Webrat::XML.attribute(element, "id") == @value.to_s)
      end

      def matches_value?(element)
        Webrat::XML.attribute(element, "value") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
      end

      def matches_html?(element)
        Webrat::XML.inner_html(element) =~ /#{Regexp.escape(@value.to_s)}/i
      end

      def matches_alt?(element)
        Webrat::XML.attribute(element, "alt") =~ /^\W*#{Regexp.escape(@value.to_s)}/i
      end

      def button_elements
        Webrat::XML.xpath_search(@dom, *ButtonField.xpath_search)
      end

      def error_message
        "Could not find button #{@value.inspect}"
      end

    end

    def find_button(value) #:nodoc:
      ButtonLocator.new(@session, dom, value).locate!
    end

  end
end

Version data entries

49 entries across 49 versions & 21 rubygems

Version Path
aslakhellesoy-webrat-0.4.4.1 lib/webrat/core/locators/button_locator.rb
casebook-webrat-0.4.4.1 lib/webrat/core/locators/button_locator.rb
cavalle-webrat-0.4.4.1 lib/webrat/core/locators/button_locator.rb
cavalle-webrat-0.4.4.2 lib/webrat/core/locators/button_locator.rb
davidtrogers-webrat-0.4.4.2 lib/webrat/core/locators/button_locator.rb
dbrady-webrat-0.4.4.1 lib/webrat/core/locators/button_locator.rb
dbrady-webrat-0.4.4.2 lib/webrat/core/locators/button_locator.rb
dbrady-webrat-0.4.4 lib/webrat/core/locators/button_locator.rb
diabolo-diabolo-webrat-0.4.4 lib/webrat/core/locators/button_locator.rb
diabolo-webrat-0.4.3 lib/webrat/core/locators/button_locator.rb
diabolo-webrat-0.4.4.1 lib/webrat/core/locators/button_locator.rb
diabolo-webrat-0.4.4.2 lib/webrat/core/locators/button_locator.rb
diabolo-webrat-0.4.4 lib/webrat/core/locators/button_locator.rb
dstrelau-webrat-0.5.1 lib/webrat/core/locators/button_locator.rb
emipair-webrat-0.0.1 lib/webrat/core/locators/button_locator.rb
futuresinc-webrat-0.4.4.100 lib/webrat/core/locators/button_locator.rb
futuresinc-webrat-0.4.4.99 lib/webrat/core/locators/button_locator.rb
garnierjm-webrat-0.4.5 lib/webrat/core/locators/button_locator.rb
hardbap-webrat-0.5.1 lib/webrat/core/locators/button_locator.rb
hardbap-webrat-0.5.2 lib/webrat/core/locators/button_locator.rb