Module: PageObject::Platforms::WatirWebDriver::Element
- Defined in:
- lib/page-object/platforms/watir_webdriver/element.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
compare this element to another to determine if they are equal.
-
#attribute(attribute_name) ⇒ String?
Get the value of a the given attribute of the element.
-
#clear ⇒ Object
clear the contents of the element.
-
#exists? ⇒ Boolean
return true if an element exists.
-
#fire_event(event_name) ⇒ Object
Fire the provided event on the current element.
-
#focus ⇒ Object
Set the focus to the current element.
-
#parent ⇒ Object
find the parent element.
-
#send_keys(*args) ⇒ Object
Send keystrokes to this element.
-
#tag_name ⇒ String
Get the tag name of this element.
-
#text ⇒ String
Get the text for the element.
-
#value ⇒ String
Get the value of this element.
-
#visible? ⇒ Boolean
return true if an element is visible.
-
#wait_until(timeout = 5, message = nil, &block) ⇒ Object
Waits until the block returns true.
-
#when_not_visible(timeout = 5) ⇒ Object
Waits until the element is not visible.
-
#when_present(timeout = 5) ⇒ Object
Waits until the element is present.
-
#when_visible(timeout = 5) ⇒ Object
Waits until the element is visible.
Instance Method Details
#==(other) ⇒ Object
compare this element to another to determine if they are equal
44 45 46 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 44 def ==(other) element == other.element end |
#attribute(attribute_name) ⇒ String?
Get the value of a the given attribute of the element. Will return the current value, even if this has been modified after the page has been loaded. More exactly, this method will return the value of the given attribute, unless that attribute is not present, in which case the value of the property with the same name is returned. If neither value is set, nil is returned. The “style” attribute is converted as best can be to a text representation with a trailing semi-colon. The following are deemed to be “boolean” attributes, and will return either “true” or “false”:
async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate
Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:
class, readonly
87 88 89 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 87 def attribute(attribute_name) element.attribute_value attribute_name end |
#clear ⇒ Object
clear the contents of the element
180 181 182 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 180 def clear element.clear end |
#exists? ⇒ Boolean
return true if an element exists
19 20 21 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 19 def exists? element.exists? end |
#fire_event(event_name) ⇒ Object
Fire the provided event on the current element
94 95 96 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 94 def fire_event(event_name) element.fire_event(event_name) end |
#focus ⇒ Object
Set the focus to the current element
111 112 113 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 111 def focus element.focus end |
#parent ⇒ Object
find the parent element
101 102 103 104 105 106 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 101 def parent parent = element.parent type = element.type if parent.tag_name.to_sym == :input cls = ::PageObject::Elements.element_class_for(parent.tag_name, type) cls.new(parent, :platform => :watir_webdriver) end |
#send_keys(*args) ⇒ Object
Send keystrokes to this element
Examples:
element.send_keys "foo" #=> value: 'foo'
element.send_keys "tet", :arrow_left, "s" #=> value: 'test'
element.send_keys [:control, 'a'], :space #=> value: ' '
173 174 175 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 173 def send_keys(*args) element.send_keys(*args) end |
#tag_name ⇒ String
Get the tag name of this element
53 54 55 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 53 def tag_name element.tag_name end |
#text ⇒ String
Get the text for the element
28 29 30 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 28 def text element.text end |
#value ⇒ String
Get the value of this element
37 38 39 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 37 def value element.value end |
#visible? ⇒ Boolean
return true if an element is visible
12 13 14 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 12 def visible? element.present? end |
#wait_until(timeout = 5, message = nil, &block) ⇒ Object
Waits until the block returns true
156 157 158 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 156 def wait_until(timeout=5, =nil, &block) Object::Watir::Wait.until(timeout, , &block) end |
#when_not_visible(timeout = 5) ⇒ Object
Waits until the element is not visible
142 143 144 145 146 147 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 142 def when_not_visible(timeout=5) Object::Watir::Wait.while(timeout, "Element still visible after #{timeout} seconds") do visible? end self end |
#when_present(timeout = 5) ⇒ Object
Waits until the element is present
120 121 122 123 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 120 def when_present(timeout=5) element.wait_until_present(timeout) self end |
#when_visible(timeout = 5) ⇒ Object
Waits until the element is visible
130 131 132 133 134 135 |
# File 'lib/page-object/platforms/watir_webdriver/element.rb', line 130 def when_visible(timeout=5) Object::Watir::Wait.until(timeout, "Element was not visible in #{timeout} seconds") do visible? end self end |