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
-
#check(field_name, value = true) ⇒ Object
Check a checkbox with the given name.
-
#click_button(label) ⇒ Object
Click a button with the given label.
-
#fill_in(name, value) ⇒ Object
Fill in a field with the given name.
-
#find_field(name) ⇒ Object
Find a field with the given name.
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 (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 |