Class: Webrat::Field
- Inherits:
-
Element
show all
- Defined in:
- lib/webrat/core/elements/field.rb
Overview
Direct Known Subclasses
ButtonField, CheckboxField, FileField, HiddenField, MultipleSelectField, PasswordField, RadioField, ResetField, SelectField, TextField, TextareaField
Instance Attribute Summary (collapse)
Attributes inherited from Element
#element
Class Method Summary
(collapse)
Instance Method Summary
(collapse)
Methods inherited from Element
#inspect, load_all, #path
Constructor Details
- (Field) initialize(*args)
65
66
67
68
|
# File 'lib/webrat/core/elements/field.rb', line 65
def initialize(*args)
super
@value = default_value
end
|
Instance Attribute Details
Returns the value of attribute value
14
15
16
|
# File 'lib/webrat/core/elements/field.rb', line 14
def value
@value
end
|
Class Method Details
+ (Object) field_class(element)
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/webrat/core/elements/field.rb', line 39
def self.field_class(element)
case element.name
when "button" then ButtonField
when "select"
if element.attributes["multiple"].nil?
SelectField
else
MultipleSelectField
end
when "textarea" then TextareaField
else
case element["type"]
when "checkbox" then CheckboxField
when "hidden" then HiddenField
when "radio" then RadioField
when "password" then PasswordField
when "file" then FileField
when "reset" then ResetField
when "submit" then ButtonField
when "button" then ButtonField
when "image" then ButtonField
else TextField
end
end
end
|
+ (Object) field_classes
24
25
26
|
# File 'lib/webrat/core/elements/field.rb', line 24
def self.field_classes
@field_classes || []
end
|
+ (Object) inherited(klass)
28
29
30
31
32
|
# File 'lib/webrat/core/elements/field.rb', line 28
def self.inherited(klass)
@field_classes ||= []
@field_classes << klass
end
|
+ (Object) load(session, element)
34
35
36
37
|
# File 'lib/webrat/core/elements/field.rb', line 34
def self.load(session, element)
return nil if element.nil?
session.elements[element.path] ||= field_class(element).new(session, element)
end
|
+ (Object) xpath_search
16
17
18
|
# File 'lib/webrat/core/elements/field.rb', line 16
def self.xpath_search
".//button|.//input|.//textarea|.//select"
end
|
+ (Object) xpath_search_excluding_hidden
20
21
22
|
# File 'lib/webrat/core/elements/field.rb', line 20
def self.xpath_search_excluding_hidden
[".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"]
end
|
Instance Method Details
- (Boolean) disabled?
79
80
81
|
# File 'lib/webrat/core/elements/field.rb', line 79
def disabled?
@element.attributes.has_key?("disabled") && @element["disabled"] != 'false'
end
|
75
76
77
|
# File 'lib/webrat/core/elements/field.rb', line 75
def id
@element["id"]
end
|
- (Object) label_text
70
71
72
73
|
# File 'lib/webrat/core/elements/field.rb', line 70
def label_text
return nil if labels.empty?
labels.first.text
end
|
- (Object) raise_error_if_disabled
83
84
85
86
|
# File 'lib/webrat/core/elements/field.rb', line 83
def raise_error_if_disabled
return unless disabled?
raise DisabledFieldError.new("Cannot interact with disabled form element (#{self})")
end
|
- (Object) set(value)
101
102
103
|
# File 'lib/webrat/core/elements/field.rb', line 101
def set(value)
@value = value
end
|
- (Object) to_query_string
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/webrat/core/elements/field.rb', line 88
def to_query_string
return nil if disabled?
query_string = case Webrat.configuration.mode
when :rails, :merb, :rack, :sinatra
build_query_string
when :mechanize
build_query_string(false)
end
query_string
end
|
105
106
107
|
# File 'lib/webrat/core/elements/field.rb', line 105
def unset
@value = default_value
end
|