Async::WebDriver SourceAsyncWebDriverScopeFields

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 click_button(label)

Click a button with the given label.

Signature

parameter label String

The label of the button.

raises NoSuchElementError

If the button does not exist.

Implementation

def click_button(label)
	element = current_scope.find_element_by_xpath("//button[text()=#{XPath::escape(label)}] | //input[@type='submit' and @value=#{XPath::escape(label)}] | //input[@type='button' and @value=#{XPath::escape(label)}]")
	
	element.click
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