Class: Webdriver::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/webdriver/element.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, connection) ⇒ Element

Returns a new instance of Element.



5
6
7
8
9
10
# File 'lib/webdriver/element.rb', line 5

def initialize(id, connection)
  @id = id

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

Instance Attribute Details

#id ⇒ Object (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/webdriver/element.rb', line 3

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object



12
13
14
15
# File 'lib/webdriver/element.rb', line 12

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

#attribute(name) ⇒ Object



68
69
70
# File 'lib/webdriver/element.rb', line 68

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

#clear! ⇒ Object



31
32
33
34
35
# File 'lib/webdriver/element.rb', line 31

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

#click! ⇒ Object



72
73
74
# File 'lib/webdriver/element.rb', line 72

def click!
  @connection.post "click"
end

#css(name) ⇒ Object



60
61
62
# File 'lib/webdriver/element.rb', line 60

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

#element(using, value) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/webdriver/element.rb', line 76

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

#elements(using, value) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/webdriver/element.rb', line 84

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

#enabled? ⇒ Boolean

form control enabled

Returns:

  • (Boolean)


27
28
29
# File 'lib/webdriver/element.rb', line 27

def enabled?
  @connection.get "enabled"
end

#property(name) ⇒ Object



64
65
66
# File 'lib/webdriver/element.rb', line 64

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

#rect ⇒ Object



52
53
54
# File 'lib/webdriver/element.rb', line 52

def rect
  @connection.get "rect"
end

#screenshot ⇒ Object



17
18
19
# File 'lib/webdriver/element.rb', line 17

def screenshot
  @connection.get "screenshot"
end

#selected? ⇒ Boolean

checkbox

Returns:

  • (Boolean)


22
23
24
# File 'lib/webdriver/element.rb', line 22

def selected?
  @connection.get "selected"
end

#tag ⇒ Object



56
57
58
# File 'lib/webdriver/element.rb', line 56

def tag
  @connection.get "name"
end

#text ⇒ Object



48
49
50
# File 'lib/webdriver/element.rb', line 48

def text
  @connection.get "text"
end

#value!(value) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/webdriver/element.rb', line 37

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