module Fields
Helpers for working with forms and form fields.
Definitions
def find_field(name)
Find a field with the given name.
Signature
-
parameter
name
String
The name of the field.
-
returns
Element
The field.
-
raises
NoSuchElementError
If the field does not exist.
Implementation
def find_field(name)
current_scope.find_element_by_xpath("//*[@name=#{XPath::escape(name)}]")
end
def fill_in(name, value)
Fill in a field with the given name.
Clears the field before filling it in.
Signature
-
parameter
name
String
The name of the field.
-
parameter
value
String
The value to fill in.
-
raises
NoSuchElementError
If the field does not exist.
Implementation
def fill_in(name, value)
element = find_field(name)
if element.tag_name == "input" || element.tag_name == "textarea"
element.clear
end
element.send_keys(value)
end
def check(field_name, value = true)
Check a checkbox with the given name.
Does not modify the checkbox if it is already in the desired state.
Signature
-
parameter
field_name
String
The name of the checkbox.
-
parameter
value
Boolean
The value to set the checkbox to.
-
raises
NoSuchElementError
If the checkbox does not exist.
Implementation
def check(field_name, value = true)
element = current_scope.find_element(xpath: "//input[@type='checkbox' and @name='#{field_name}']")
if element.checked? != value
element.click
end
end