Module: WatirRobot::Element
- Included in:
- KeywordLibrary
- Defined in:
- lib/watir_robot/keywords/element.rb
Overview
Functionality related to HTML elements in a generic, global context
Instance Method Summary collapse
-
#click_element(loc) ⇒ Object
Click any HTML element.
-
#element_should_be_visible(loc) ⇒ Object
Verify that an element is visible.
-
#element_should_not_be_visible(loc) ⇒ Object
Verify that an element is not visible.
-
#element_text_should_be(loc, text) ⇒ Object
Verify that an element’s text matches a specific value.
-
#element_text_should_contain(loc, text) ⇒ Object
Verify that an element’s text contains a specific value.
-
#focus(loc) ⇒ Object
Set focus to element.
-
#get_element_attribute(loc, attr) ⇒ String
Get the value of an attribute for an element.
-
#get_element_text(loc) ⇒ String
Get an element’s text.
-
#send_keys(loc, text) ⇒ Object
Type text into the given text field (alternate for “Type Text”).
-
#type_text(loc, text) ⇒ Object
Type text into the given text field (alternate for “Send Keys”).
Instance Method Details
#click_element(loc) ⇒ Object
Click any HTML element
36 37 38 |
# File 'lib/watir_robot/keywords/element.rb', line 36 def click_element(loc) @browser.element(parse_location(loc)).click end |
#element_should_be_visible(loc) ⇒ Object
Verify that an element is visible
76 77 78 79 |
# File 'lib/watir_robot/keywords/element.rb', line 76 def element_should_be_visible(loc) raise(Exception::ElementVisibilityError, "The element described by #{parse_location(loc)} is not visible.") unless @browser.element(parse_location(loc)).visible? end |
#element_should_not_be_visible(loc) ⇒ Object
Verify that an element is not visible
86 87 88 89 |
# File 'lib/watir_robot/keywords/element.rb', line 86 def element_should_not_be_visible(loc) raise(Exception::ElementVisibilityError, "The element described by #{parse_location(loc)} is visible erroneously.") if @browser.element(parse_location(loc)).visible? end |
#element_text_should_be(loc, text) ⇒ Object
Verify that an element’s text matches a specific value
107 108 109 110 |
# File 'lib/watir_robot/keywords/element.rb', line 107 def element_text_should_be(loc, text) raise(Exception::ElementMatchError, "The element's text #{@browser.element(parse_location(loc)).text} does not equal #{text}.") unless @browser.element(parse_location(loc)).text == text end |
#element_text_should_contain(loc, text) ⇒ Object
Verify that an element’s text contains a specific value
97 98 99 100 |
# File 'lib/watir_robot/keywords/element.rb', line 97 def element_text_should_contain(loc, text) raise(Exception::ElementMatchError, "The element's text #{@browser.element(parse_location(loc)).text} does not contain the text #{text}.") unless @browser.element(parse_location(loc)).text.include? text end |
#focus(loc) ⇒ Object
Set focus to element
45 46 47 |
# File 'lib/watir_robot/keywords/element.rb', line 45 def focus(loc) @browser.element(parse_location(loc)).focus end |
#get_element_attribute(loc, attr) ⇒ String
Get the value of an attribute for an element
17 18 19 |
# File 'lib/watir_robot/keywords/element.rb', line 17 def get_element_attribute(loc, attr) @browser.element(parse_location(loc)).attribute_value(attr) end |
#get_element_text(loc) ⇒ String
Get an element’s text
27 28 29 |
# File 'lib/watir_robot/keywords/element.rb', line 27 def get_element_text(loc) @browser.element(parse_location(loc)).text end |
#send_keys(loc, text) ⇒ Object
Type text into the given text field (alternate for “Type Text”)
55 56 57 |
# File 'lib/watir_robot/keywords/element.rb', line 55 def send_keys(loc, text) @browser.element(parse_location(loc)).send_keys(text) end |
#type_text(loc, text) ⇒ Object
Type text into the given text field (alternate for “Send Keys”)
65 66 67 |
# File 'lib/watir_robot/keywords/element.rb', line 65 def type_text(loc, text) @browser.element(parse_location(loc)).send_keys(text) end |