lib/element.rb in gridium-1.0.25 vs lib/element.rb in gridium-1.0.26
- old
+ new
@@ -4,11 +4,11 @@
class Element
attr_reader :name, :by, :locator
- def initialize(name, by, locator)
+ def initialize(name, by, locator, opts = {})
@name = name
@by = by
@locator = locator
@element_screenshot = nil #used to store the path of element screenshots for comparison
@@ -16,10 +16,13 @@
@driver = Driver.driver
# selenium web element
@element = nil
+ # should always be driver unless getting an element's child
+ @parent ||= (opts[:parent] || @driver)
+
#how long to wait between clearing an input and sending keys to it
@text_padding_time = 0.15
end
def to_s
@@ -30,11 +33,11 @@
if stale?
wait = Selenium::WebDriver::Wait.new :timeout => Gridium.config.element_timeout, :interval => 1
if Gridium.config.visible_elements_only
wait.until { @element = displayed_element }
else
- wait.until { @element = @driver.find_element(@by, @locator); Log.debug("Finding element #{self}..."); @element.enabled? }
+ wait.until { @element = @parent.find_element(@by, @locator); Log.debug("Finding element #{self}..."); @element.enabled? }
end
end
@element
end
@@ -45,11 +48,11 @@
def displayed_element
found_element = nil
#Found an issue where the element would go stale after it's found
begin
- elements = @driver.find_elements(@by, @locator)
+ elements = @parent.find_elements(@by, @locator)
elements.each do |element|
if element.displayed? #removed check for element.enabled
found_element = element; #this will always return the last displayed element
end
end
@@ -88,10 +91,16 @@
def attribute(name)
element.attribute(name)
end
+ def css_value(name)
+ element.css_value(name)
+ end
+
+
+
def present?
return element.enabled?
rescue StandardError => error
Log.debug("element.present? is false because this error was rescued: #{error}")
return false
@@ -164,14 +173,19 @@
end
alias_method :text=, :send_keys
+
def location
element.location
end
+ def location_once_scrolled_into_view
+ element.location_once_scrolled_into_view
+ end
+
def hover_over
Log.debug("Hovering over element (#{self.to_s})...")
# @driver.mouse.move_to(element) # Note: Doesn't work with Selenium 2.42 bindings for Firefox v31
# @driver.action.move_to(element).perform
# @driver.mouse_over(@locator)
@@ -252,11 +266,11 @@
#
# @return [Element] element
#
def find_element(by, locator)
Log.debug('Finding element...')
- element.find_element(by, locator)
+ Element.new("Child of #{@name}", by, locator, parent: @element)
end
#
# Search for an elements within this element
#
@@ -264,10 +278,11 @@
# @param [String] locator
#
# @return [Array] elements
#
def find_elements(by, locator)
- element.find_elements(by, locator)
+ elements = element.find_elements(by, locator)
+ elements.map {|_| Element.new("Child of #{@name}", by, locator, parent: @element)}
end
def save_element_screenshot
Log.debug ("Capturing screenshot of element...")
self.scroll_into_view