Sha256: 8fd5eb20a3aa0232fd992d0288fbe0298e62ecb977bc6a810aa5e60cc486acac

Contents?: true

Size: 1.86 KB

Versions: 10

Compression:

Stored size: 1.86 KB

Contents

module Webdriver
  class Element
    attr_reader :id

    def initialize(id, connection)
      @id = id

      @session_connection = connection
      @connection = Webdriver::PrefixConnection.new "element/#{@id}", connection
    end

    def ==(other)
      return false unless other.is_a? Webdriver::Element
      @id == other.id
    end

    def location_in_view
      @connection.get "location_in_view"
    end

    def size
      @connection.get "size"
    end

    def screenshot
      @connection.get "screenshot"
    end

    def displayed?
      @connection.get "displayed"
    end

    # checkbox
    def selected?
      @connection.get "selected"
    end

    # form control enabled
    def enabled?
      @connection.get "enabled"
    end

    def clear!
      @connection.post "clear"
      click!
      self
    end

    def value! value
      value_string = value.to_s
      if value_string == ""
        clear!
      else
        @connection.post "value", {}, {
          value: [value_string]
        }
      end
    end

    def text
      @connection.get "text"
    end

    def rect
      @connection.get "rect"
    end

    def tag
      @connection.get "name"
    end

    def css name
      @connection.get File.join("css", name)
    end

    def property name
      @connection.get File.join("property", name)
    end

    def attribute name
      @connection.get File.join("attribute", name)
    end

    def click!
      @connection.post "click"
    end

    def element using, value
      el = @connection.post "element", {}, {
        using: using,
        value: value
      }
      Webdriver::Element.new el["ELEMENT"], @session_connection
    end

    def elements using, value
      resp = @connection.post "elements", {}, {
        using: using,
        value: value
      }
      resp.map { |el| Webdriver::Element.new el["ELEMENT"], @session_connection }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
webdriver-0.19.0 lib/webdriver/element.rb
webdriver-0.18.0 lib/webdriver/element.rb
webdriver-0.17.0 lib/webdriver/element.rb
webdriver-0.16.0 lib/webdriver/element.rb
webdriver-0.15.0 lib/webdriver/element.rb
webdriver-0.14.0 lib/webdriver/element.rb
webdriver-0.13.0 lib/webdriver/element.rb
webdriver-0.12.0 lib/webdriver/element.rb
webdriver-0.11.1 lib/webdriver/element.rb
webdriver-0.11.0 lib/webdriver/element.rb