class PageObject::Elements::Element
Contains functionality that is common across all elements.
@see PageObject::Platforms::Watir::Element for the Watir version of all common methods
Attributes
Public Class Methods
# File lib/page-object/elements/element.rb, line 15 def initialize(element) @element = element @platform = PageObject::Platforms::Watir::PageObject.new(@element) end
specify plural form of element
# File lib/page-object/elements/element.rb, line 42 def self.plural_form "#{self.to_s.split('::')[-1]. gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2'). tr("-", "_"). downcase}s" end
Public Instance Methods
compare this element to another to determine if they are equal
# File lib/page-object/elements/element.rb, line 75 def ==(other) other.is_a? self.class and element == other.element end
Keeps checking until the element exists
@param [Integer] (defaults to: 5) seconds to wait before timing out
# File lib/page-object/elements/element.rb, line 66 def check_exists(timeout=::PageObject.default_element_wait) timed_loop(timeout) do |element| element.exists? end end
Keeps checking until the element is visible
@param [Integer] (defaults to: 5) seconds to wait before timing out
# File lib/page-object/elements/element.rb, line 55 def check_visible(timeout=::PageObject.default_element_wait) timed_loop(timeout) do |element| element.present? end end
Return all elements that are children of this element
# File lib/page-object/elements/element.rb, line 116 def children(opt={}) children = element.children(opt) children.collect {|child| pageobject_wrapper(child)} end
return true if the element is not enabled
# File lib/page-object/elements/element.rb, line 23 def disabled? not enabled? end
# File lib/page-object/elements/element.rb, line 34 def drag_and_drop_on(droppable) droppable_native = droppable.kind_of?(PageObject::Elements::Element) ? droppable.element : droppable element.drag_and_drop_on(droppable_native) end
Return the element that exists at the same level of the DOM immediately after this element
# File lib/page-object/elements/element.rb, line 100 def following_sibling(opt={}) sibling = element.following_sibling(opt) pageobject_wrapper(sibling) end
Return all elements that exist at the same level of the DOM immediately after this element
# File lib/page-object/elements/element.rb, line 134 def following_siblings(opt={}) siblings = element.following_siblings(opt) siblings.collect {|sibling| pageobject_wrapper(sibling)} end
@private delegate calls to driver element
# File lib/page-object/elements/element.rb, line 178 def method_missing(method, *args, &block) if element.respond_to?(method) element.send(method, *args, &block) else super end end
# File lib/page-object/elements/element.rb, line 172 def name element.attribute(:name) end
find the parent element
# File lib/page-object/elements/element.rb, line 82 def parent(opt = {}) parent = element.parent(opt) pageobject_wrapper(parent) end
Return the element that exists at the same level of the DOM immediately prior to this element
# File lib/page-object/elements/element.rb, line 91 def preceding_sibling(opt = {}) sibling = element.preceding_sibling(opt) pageobject_wrapper(sibling) end
Return all elements that exist at the same level of the DOM immediately prior to this element
# File lib/page-object/elements/element.rb, line 125 def preceding_siblings(opt={}) siblings = element.preceding_siblings(opt) siblings.collect {|sibling| pageobject_wrapper(sibling)} end
return true if the element exists and is visible
# File lib/page-object/elements/element.rb, line 30 def present? element.present? end
# File lib/page-object/elements/element.rb, line 186 def respond_to_missing?(m,*args) element.respond_to?(m) || super end
Return all elements that are direct children of this element's parent
# File lib/page-object/elements/element.rb, line 108 def siblings(opt={}) siblings = element.siblings(opt) siblings.collect {|sibling| pageobject_wrapper(sibling)} end
Waits until the block returns true
@param [Integer] (defaults to: 5) seconds to wait before timing out @param [String] the message to display if the event timeouts @param the block to execute when the event occurs
# File lib/page-object/elements/element.rb, line 168 def wait_until(timeout=::PageObject.default_element_wait, message=nil, &block) element.wait_until(timeout: timeout, message: message, &block) end
Waits until the element is not present
@param [Integer] (defaults to: 5) seconds to wait before timing out
# File lib/page-object/elements/element.rb, line 156 def when_not_present(timeout=::PageObject.default_element_wait) element.wait_while(timeout: timeout, message: "Element still present in #{timeout} seconds", &:present?) end
Waits until the element is present
@param [Integer] (defaults to: 5) seconds to wait before timing out
# File lib/page-object/elements/element.rb, line 144 def when_present(timeout=::PageObject.default_element_wait) element.wait_until(timeout: timeout, message: "Element not present in #{timeout} seconds", &:present?) self end
Protected Instance Methods
# File lib/page-object/elements/element.rb, line 192 def pageobject_wrapper(watir_object) type = element.type if watir_object.tag_name.to_sym == :input cls = ::PageObject::Elements.element_class_for(watir_object.tag_name, type) cls.new(watir_object.to_subtype) end
Private Instance Methods
# File lib/page-object/elements/element.rb, line 200 def timed_loop(timeout) end_time = ::Time.now + timeout until ::Time.now > end_time result = yield(self) return result if result sleep 0.5 end false end