Class: Watir::Locators::Element::SelectorBuilder::XPath

Inherits:
Object
  • Object
show all
Includes:
Exception, XpathSupport
Defined in:
lib/watir/locators/element/selector_builder/xpath.rb

Constant Summary collapse

CAN_NOT_BUILD =
%i[visible visible_text visible_label_element].freeze
LOCATOR =
:xpath

Constants included from XpathSupport

Watir::Locators::Element::SelectorBuilder::XpathSupport::LOWERCASE_LETTERS, Watir::Locators::Element::SelectorBuilder::XpathSupport::UPPERCASE_LETTERS

Instance Method Summary collapse

Methods included from XpathSupport

downcase, escape

Instance Method Details

#build(selector) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/watir/locators/element/selector_builder/xpath.rb', line 15

def build(selector)
  @selector = selector
  @valid_attributes = build_valid_attributes

  @built = (@selector.keys & CAN_NOT_BUILD).each_with_object({}) do |key, hash|
    hash[key] = @selector.delete(key)
  end

  index = @selector.delete(:index)
  @adjacent = @selector.delete(:adjacent)
  @scope = @selector.delete(:scope)

  xpath = "#{start_string}" \
          "#{adjacent_string}" \
          "#{tag_string}" \
          "#{class_string}" \
          "#{text_string}" \
          "#{additional_string}" \
          "#{label_element_string}" \
          "#{attribute_string}"

  @built[:xpath] = index ? add_index(xpath, index) : xpath
  @built
end