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

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

Defined Under Namespace

Modules: XpathSupport Classes: RegexpDisassembler, XPath

Constant Summary collapse

WILDCARD_ATTRIBUTE =
/^(aria|data)_(.+)$/.freeze
INTEGER_CLASS =
Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4') ? Fixnum : Integer
VALID_WHATS =
Hash.new([String, Regexp, TrueClass, FalseClass]).merge(adjacent: [::Symbol],
xpath: [String],
css: [String],
index: [INTEGER_CLASS],
visible: [TrueClass, FalseClass],
tag_name: [String, Regexp, ::Symbol],
visible_text: [String, Regexp],
scope: [Hash],
text: [String, Regexp]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(valid_attributes, query_scope) ⇒ SelectorBuilder

Returns a new instance of SelectorBuilder.


20
21
22
23
24
# File 'lib/watir/locators/element/selector_builder.rb', line 20

def initialize(valid_attributes, query_scope)
  @valid_attributes = valid_attributes
  @custom_attributes = []
  @query_scope = query_scope
end

Instance Attribute Details

#builtObject (readonly)

Returns the value of attribute built


6
7
8
# File 'lib/watir/locators/element/selector_builder.rb', line 6

def built
  @built
end

#custom_attributesObject (readonly)

Returns the value of attribute custom_attributes


6
7
8
# File 'lib/watir/locators/element/selector_builder.rb', line 6

def custom_attributes
  @custom_attributes
end

Instance Method Details

#build(selector) ⇒ Object


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/watir/locators/element/selector_builder.rb', line 26

def build(selector)
  @selector = selector

  deprecated_locators
  normalize_selector
  inspected = selector.inspect
  scope = @query_scope unless @selector.key?(:scope) || @query_scope.is_a?(Watir::Browser)

  @built = wd_locators.empty? ? build_wd_selector(@selector) : @selector
  @built.delete(:index) if @built[:index]&.zero?
  @built[:scope] = scope if scope

  Watir.logger.info "Converted #{inspected} to #{@built.inspect}"
  @built
end

#wd_locatorsObject


42
43
44
# File 'lib/watir/locators/element/selector_builder.rb', line 42

def wd_locators
  Watir::Locators::W3C_FINDERS & @selector.keys
end