Sha256: 37091b427abdc335cf42d49a46862319c1c233bfcb6d87a5cb9624989b78dec5

Contents?: true

Size: 699 Bytes

Versions: 6

Compression:

Stored size: 699 Bytes

Contents

require "webrat/core_extensions/detect_mapped"
require "webrat/core/locators/locator"

module Webrat
  module Locators

    class LabelLocator < Locator # :nodoc:

      def locate
        Label.load(@session, label_element)
      end

      def label_element
        label_elements.detect do |label_element|
          text(label_element) =~ /^\W*#{Regexp.escape(@value.to_s)}\b/i
        end
      end

      def label_elements
        Webrat::XML.xpath_search(@dom, Label.xpath_search)
      end

      def text(label_element)
        str = Webrat::XML.all_inner_text(label_element)
        str.gsub!("\n","")
        str.strip!
        str.squeeze!(" ")
        str
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 4 rubygems

Version Path
cavalle-webrat-0.4.4.1 lib/webrat/core/locators/label_locator.rb
cavalle-webrat-0.4.4.2 lib/webrat/core/locators/label_locator.rb
dbrady-webrat-0.4.4.1 lib/webrat/core/locators/label_locator.rb
dbrady-webrat-0.4.4 lib/webrat/core/locators/label_locator.rb
diabolo-diabolo-webrat-0.4.4 lib/webrat/core/locators/label_locator.rb
diabolo-webrat-0.4.3 lib/webrat/core/locators/label_locator.rb