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


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

def build(selector)
  @selector = selector

  @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
  xpath << adjacent_string
  xpath << tag_string
  xpath << class_string
  xpath << text_string
  xpath << additional_string
  xpath << label_element_string
  xpath << attribute_string

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