Class: Watir::ButtonLocator

Inherits:
ElementLocator show all
Defined in:
lib/watir-webdriver/locators/button_locator.rb

Constant Summary

Constants inherited from ElementLocator

ElementLocator::WD_FINDERS

Instance Method Summary collapse

Methods inherited from ElementLocator

#assert_valid_as_attribute, #attribute_expression, #by_id, #check_type, #delete_regexps_from, #equal_pair, #fetch_value, #find_all_by_multiple, #find_all_by_one, #find_first_by_multiple, #find_first_by_one, #initialize, #locate, #normalize_selector, #normalized_selector, #wd_find_all_by, #wd_find_by_regexp_selector, #wd_find_first_by

Constructor Details

This class inherits a constructor from Watir::ElementLocator

Instance Method Details

#build_xpath(selectors) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/watir-webdriver/locators/button_locator.rb', line 8

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

#lhs_for(key) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/watir-webdriver/locators/button_locator.rb', line 30

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

#locate_allObject



4
5
6
# File 'lib/watir-webdriver/locators/button_locator.rb', line 4

def locate_all
  find_all_by_multiple
end

#matches_selector?(rx_selector, element) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/watir-webdriver/locators/button_locator.rb', line 40

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

#tag_name_matches?(element, _) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/watir-webdriver/locators/button_locator.rb', line 53

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