Class: Webrat::Field
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
#initialize(*args) ⇒ Field
Returns a new instance of Field.
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
.field_class(element) ⇒ Object
.field_classes ⇒ Object
24
25
26
|
# File 'lib/webrat/core/elements/field.rb', line 24
def self.field_classes
@field_classes || []
end
|
.inherited(klass) ⇒ Object
28
29
30
31
32
|
# File 'lib/webrat/core/elements/field.rb', line 28
def self.inherited(klass)
@field_classes ||= []
@field_classes << klass
end
|
.load(session, element) ⇒ Object
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
|
.xpath_search ⇒ Object
16
17
18
|
# File 'lib/webrat/core/elements/field.rb', line 16
def self.xpath_search
".//button|.//input|.//textarea|.//select"
end
|
.xpath_search_excluding_hidden ⇒ Object
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
#disabled? ⇒ Boolean
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
|
#label_text ⇒ Object
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
|
#raise_error_if_disabled ⇒ Object
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
|
#set(value) ⇒ Object
101
102
103
|
# File 'lib/webrat/core/elements/field.rb', line 101
def set(value)
@value = value
end
|
#to_query_string ⇒ Object
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
|