class AutomationObject::State::ElementHash

Element hash composite for managing state

Public Instance Methods

utilize() click to toggle source

@return [Hash<String, AutomationObject::State::ElementProxy>] Selenium proxy

# File lib/automation_object/state/element_hash.rb, line 15
def utilize
  return cache if cache

  elements = driver.find_elements(*blue_prints.selector_params)
  self.cache = {}

  elements.each do |element|
    # Want to wrap element, before sending for method!
    # That will help us include custom methods, etc...
    wrapped_element = ElementProxy.new(self, element)
    hash_key = wrapped_element.send(blue_prints.define_elements_by) # Send to wrapped state proxy

    cache[hash_key] = wrapped_element
  end

  @active = true
  cache
end