Module: Async::WebDriver::Scope::Fields

Included in:
Element, Async::WebDriver::Session
Defined in:
lib/async/webdriver/scope/fields.rb

Overview

Helpers for working with forms and form fields.

Instance Method Summary collapse

Instance Method Details

#check(field_name, value = true) ⇒ Object

Check a checkbox with the given name.

Does not modify the checkbox if it is already in the desired state.



54
55
56
57
58
59
60
# File 'lib/async/webdriver/scope/fields.rb', line 54

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

#click_button(label) ⇒ Object

Click a button with the given label.



41
42
43
44
45
# File 'lib/async/webdriver/scope/fields.rb', line 41

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

#fill_in(name, value) ⇒ Object

Fill in a field with the given name.

Clears the field before filling it in.



28
29
30
31
32
33
34
35
36
# File 'lib/async/webdriver/scope/fields.rb', line 28

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

#find_field(name) ⇒ Object

Find a field with the given name.



17
18
19
# File 'lib/async/webdriver/scope/fields.rb', line 17

def find_field(name)
	current_scope.find_element_by_xpath("//*[@name=#{XPath::escape(name)}]")
end