Sha256: 86eb3fc3098eca5e7e60183d21521e186784c3f45c520cf44ebb6eb1b935fd68

Contents?: true

Size: 892 Bytes

Versions: 3

Compression:

Stored size: 892 Bytes

Contents

module Element

  def self.included(base)
    base.extend FindElement
  end

  module FindElement

    # @method element(element_name, locator, error=true)
    # @param element_name [:Symbol]
    # @param locator [Hash]
    # @param error [Boolean] -- default true
    # @return [Selenium::WebDriver::Element]
    # @return [Boolean false] -- if element not found and error parameter = false

    def element(element_name, locator, error=true)
      send(:define_method, element_name) do
        wait = Selenium::WebDriver::Wait.new(:timeout => 0.5)
        begin
          wait.until { @driver.find_element(locator) }
        rescue Selenium::WebDriver::Error::TimeOutError
          if error
            raise "Could not find element using '#{locator.first.key}=#{locator.first.key}' strategy"
          else
            return false
          end
        end
      end
    end


  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
web-object-0.4 lib/web-object/element.rb
web-object-0.3 lib/web-object/element.rb
web-object-0.2 lib/web-object/element.rb