Class: Watir::Locators::Element::SelectorBuilder
- Inherits:
-
Object
- Object
- Watir::Locators::Element::SelectorBuilder
show all
- Defined in:
- lib/watir-webdriver/locators/element/selector_builder.rb,
lib/watir-webdriver/locators/element/selector_builder/css.rb,
lib/watir-webdriver/locators/element/selector_builder/xpath.rb
Defined Under Namespace
Classes: CSS, XPath
Constant Summary
collapse
- VALID_WHATS =
[String, Regexp]
- WILDCARD_ATTRIBUTE =
/^(aria|data)_(.+)$/
Instance Method Summary
collapse
Constructor Details
#initialize(parent, selector, valid_attributes) ⇒ SelectorBuilder
Returns a new instance of SelectorBuilder.
11
12
13
14
15
|
# File 'lib/watir-webdriver/locators/element/selector_builder.rb', line 11
def initialize(parent, selector, valid_attributes)
@parent = parent @selector = selector
@valid_attributes = valid_attributes
end
|
Instance Method Details
#build(selector) ⇒ Object
47
48
49
|
# File 'lib/watir-webdriver/locators/element/selector_builder.rb', line 47
def build(selector)
given_xpath_or_css(selector) || build_wd_selector(selector)
end
|
#check_type(how, what) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/watir-webdriver/locators/element/selector_builder.rb', line 30
def check_type(how, what)
case how
when :index
unless what.is_a?(Fixnum)
raise TypeError, "expected Fixnum, got #{what.inspect}:#{what.class}"
end
else
unless VALID_WHATS.any? { |t| what.is_a? t }
raise TypeError, "expected one of #{VALID_WHATS.inspect}, got #{what.inspect}:#{what.class}"
end
end
end
|
#normalized_selector ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/watir-webdriver/locators/element/selector_builder.rb', line 17
def normalized_selector
selector = {}
@selector.each do |how, what|
check_type(how, what)
how, what = normalize_selector(how, what)
selector[how] = what
end
selector
end
|
#should_use_label_element? ⇒ Boolean
43
44
45
|
# File 'lib/watir-webdriver/locators/element/selector_builder.rb', line 43
def should_use_label_element?
!valid_attribute?(:label)
end
|
#xpath_builder ⇒ Object
51
52
53
|
# File 'lib/watir-webdriver/locators/element/selector_builder.rb', line 51
def xpath_builder
@xpath_builder ||= xpath_builder_class.new(should_use_label_element?)
end
|