Sha256: 072b9285b3828fbaf1d3fb692f7e7ec6ae52b54caf0a9c4e800525a76c7b8e1a
Contents?: true
Size: 1.74 KB
Versions: 2
Compression:
Stored size: 1.74 KB
Contents
module Watir class ButtonLocator < ElementLocator VALID_TYPES = %w[button reset submit image] def locate_all find_all_by_multiple end private def wd_find_first_by(how, what) if how == :tag_name how = :xpath what = ".//button | .//input[#{attribute_expression :type => VALID_TYPES}]" end super 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] = VALID_TYPES 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?(element, rx_selector) 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 def validate_element(element) return if element.tag_name == "input" && !VALID_TYPES.include?(element.attribute(:type)) super end end # ButtonLocator end # Watir
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
watir-webdriver-0.0.9 | lib/watir-webdriver/locators/button_locator.rb |
watir-webdriver-0.0.8 | lib/watir-webdriver/locators/button_locator.rb |