Class: Watir::Locators::Element::SelectorBuilder
- Inherits:
-
Object
- Object
- Watir::Locators::Element::SelectorBuilder
- 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
Direct Known Subclasses
Anchor::SelectorBuilder, Button::SelectorBuilder, Cell::SelectorBuilder, Option::SelectorBuilder, Row::SelectorBuilder, TextArea::SelectorBuilder, TextField::SelectorBuilder
Defined Under Namespace
Modules: XpathSupport Classes: RegexpDisassembler, XPath
Constant Summary collapse
- WILDCARD_ATTRIBUTE =
/^(aria|data)_(.+)$/
- VALID_WHATS =
Hash.new([String, Regexp, TrueClass, FalseClass]).merge(adjacent: [::Symbol], xpath: [String], css: [String], index: [Integer], visible: [TrueClass, FalseClass], tag_name: [String, Regexp, ::Symbol], visible_text: [String, Regexp], scope: [Hash], text: [String, Regexp]).freeze
Instance Attribute Summary collapse
-
#built ⇒ Object
readonly
Returns the value of attribute built.
-
#custom_attributes ⇒ Object
readonly
Returns the value of attribute custom_attributes.
Instance Method Summary collapse
-
#build(selector) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity:.
-
#initialize(valid_attributes, query_scope) ⇒ SelectorBuilder
constructor
A new instance of SelectorBuilder.
-
#wd_locators ⇒ Object
rubocop:enable Metrics/PerceivedComplexity:.
Constructor Details
#initialize(valid_attributes, query_scope) ⇒ SelectorBuilder
Returns a new instance of SelectorBuilder.
21 22 23 24 25 |
# File 'lib/watir/locators/element/selector_builder.rb', line 21 def initialize(valid_attributes, query_scope) @valid_attributes = valid_attributes @custom_attributes = [] @query_scope = query_scope end |
Instance Attribute Details
#built ⇒ Object (readonly)
Returns the value of attribute built.
8 9 10 |
# File 'lib/watir/locators/element/selector_builder.rb', line 8 def built @built end |
#custom_attributes ⇒ Object (readonly)
Returns the value of attribute custom_attributes.
8 9 10 |
# File 'lib/watir/locators/element/selector_builder.rb', line 8 def custom_attributes @custom_attributes end |
Instance Method Details
#build(selector) ⇒ Object
rubocop:disable Metrics/PerceivedComplexity:
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/watir/locators/element/selector_builder.rb', line 28 def build(selector) @selector = selector normalize_selector inspected = selector.inspect scope = @query_scope unless @selector.key?(:scope) || @query_scope.is_a?(Watir::Browser) @built = if scope.is_a? Watir::ShadowRoot raise ArgumentError, ':xpath not supported when locating elements from shadow root' if @selector[:xpath] @selector[:css] ||= '*' @selector else wd_locators.empty? ? build_wd_selector(@selector) : @selector end @built.delete(:index) if @built[:index]&.zero? @built[:scope] = scope if scope Watir.logger.info "Converted #{inspected} to #{@built.inspect}" @built end |
#wd_locators ⇒ Object
rubocop:enable Metrics/PerceivedComplexity:
52 53 54 |
# File 'lib/watir/locators/element/selector_builder.rb', line 52 def wd_locators Watir::Locators::W3C_FINDERS & @selector.keys end |