class Watir::Locators::Button::SelectorBuilder::XPath

Private Instance Methods

button_string(text: nil, type: nil) click to toggle source
# File lib/watir/locators/button/selector_builder/xpath.rb, line 22
def button_string(text: nil, type: nil)
  string = process_attribute(:tag_name, 'button')
  string << " and #{process_attribute(:text, text)}" unless text.nil?
  string << " and #{input_types(type)}" unless type.nil?
  string
end
input_string(text: nil, type: nil) click to toggle source
# File lib/watir/locators/button/selector_builder/xpath.rb, line 29
def input_string(text: nil, type: nil)
  string = process_attribute(:tag_name, 'input')
  type = nil if type.eql?(true)
  string << " and (#{input_types(type)})"
  if text
    string << " and #{process_attribute(:value, text)}"
    @built.delete(:value)
  end
  string
end
input_types(type = nil) click to toggle source
# File lib/watir/locators/button/selector_builder/xpath.rb, line 65
def input_types(type = nil)
  types = if type.eql?(nil)
            Watir::Button::VALID_TYPES
          elsif Watir::Button::VALID_TYPES.include?(type)
            [type]
          elsif type.eql?(true) || type.eql?(false)
            [type]
          else
            msg = "Button Elements can not be located by input type: #{type}"
            raise LocatorException, msg
          end
  types.map { |button_type|
    predicate_expression(:type, button_type)
  }.compact.join(' or ')
end
predicate_conversion(key, regexp) click to toggle source
Calls superclass method
# File lib/watir/locators/button/selector_builder/xpath.rb, line 59
def predicate_conversion(key, regexp)
  res = key == :text ? super(:contains_text, regexp) : super
  @built[key] = @built.delete(:contains_text) if @built.key?(:contains_text)
  res
end
tag_string() click to toggle source
Calls superclass method
# File lib/watir/locators/button/selector_builder/xpath.rb, line 8
def tag_string
  return super if @adjacent

  # Selector builder ignores tag name and builds for both button elements and input elements of type button
  @selector.delete(:tag_name)

  type = @selector.delete(:type)
  text = @selector.delete(:text)

  string = "(#{button_string(text: text, type: type)})"
  string << " or (#{input_string(text: text, type: type)})" unless type.eql?(false)
  "[#{string}]"
end
text_string() click to toggle source

value locator needs to match input value, button text or button value

Calls superclass method
# File lib/watir/locators/button/selector_builder/xpath.rb, line 41
def text_string
  return super if @adjacent

  # :text locator is already dealt with in #tag_name_string
  value = @selector.delete(:value)

  case value
  when nil
    ''
  when Regexp
    res = "[#{predicate_conversion(:text, value)} or #{predicate_conversion(:value, value)}]"
    @built.delete(:text)
    res
  else
    "[#{predicate_expression(:text, value)} or #{predicate_expression(:value, value)}]"
  end
end