Class: Watir::TextFieldLocator
Constant Summary
collapse
- NON_TEXT_TYPES =
%w[file radio checkbox submit reset image button hidden url datetime date month week time datetime-local range color]
- NEGATIVE_TYPE_EXPR =
TODO: better way of finding input text fields?
NON_TEXT_TYPES.map { |t| "@type!=#{t.inspect}" }.join(" and ")
ElementLocator::WD_FINDERS
Instance Method Summary
collapse
#assert_valid_as_attribute, #attribute_expression, #by_id, #check_type, #delete_regexps_from, #equal_pair, #fetch_value, #find_all_by_multiple, #find_all_by_one, #find_first_by_multiple, #find_first_by_one, #initialize, #locate, #normalize_selector, #normalized_selector, #wd_find_all_by, #wd_find_by_regexp_selector, #wd_find_first_by
Instance Method Details
#build_xpath(selectors) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/watir-webdriver/locators/text_field_locator.rb', line 12
def build_xpath(selectors)
return if selectors.values.any? { |e| e.kind_of? Regexp }
selectors.delete(:tag_name) || raise("internal error: no tag_name?!")
@building = :textarea
textarea_attr_exp = attribute_expression(selectors)
@building = :input
input_attr_exp = attribute_expression(selectors)
xpath = ".//input[(not(@type) or (#{NEGATIVE_TYPE_EXPR}))"
xpath << " and #{input_attr_exp}" unless input_attr_exp.empty?
xpath << "] "
xpath << "| .//textarea"
xpath << "[#{textarea_attr_exp}]" unless textarea_attr_exp.empty?
p :build_xpath => xpath if $DEBUG
xpath
end
|
#lhs_for(key) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/watir-webdriver/locators/text_field_locator.rb', line 34
def lhs_for(key)
if @building == :input && [:text, :label].include?(key)
"@value"
elsif @building == :textarea && [:value, :label].include?(key)
"text()"
else
super
end
end
|
#locate_all ⇒ Object
8
9
10
|
# File 'lib/watir-webdriver/locators/text_field_locator.rb', line 8
def locate_all
find_all_by_multiple
end
|
#matches_selector?(rx_selector, element) ⇒ Boolean
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/watir-webdriver/locators/text_field_locator.rb', line 44
def matches_selector?(rx_selector, element)
rx_selector = rx_selector.dup
[:text, :value, :label].each do |key|
if rx_selector.has_key?(key)
correct_key = element.tag_name == 'input' ? :value : :text
rx_selector[correct_key] = rx_selector.delete(key)
end
end
super
end
|
#tag_name_matches?(element, _) ⇒ Boolean
57
58
59
|
# File 'lib/watir-webdriver/locators/text_field_locator.rb', line 57
def tag_name_matches?(element, _)
!!(/^(input|textarea)$/ === element.tag_name)
end
|