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

#idObject (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



80
81
82
# File 'lib/webdriver/element.rb', line 80

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

#clear!Object



43
44
45
46
47
# File 'lib/webdriver/element.rb', line 43

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

#click!Object



84
85
86
# File 'lib/webdriver/element.rb', line 84

def click!
  @connection.post "click"
end

#css(name) ⇒ Object



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

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

#displayed?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/webdriver/element.rb', line 29

def displayed?
  @connection.get "displayed"
end

#element(using, value) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/webdriver/element.rb', line 88

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

#elements(using, value) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/webdriver/element.rb', line 96

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)


39
40
41
# File 'lib/webdriver/element.rb', line 39

def enabled?
  @connection.get "enabled"
end

#location_in_viewObject



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

def location_in_view
  @connection.get "location_in_view"
end

#property(name) ⇒ Object



76
77
78
# File 'lib/webdriver/element.rb', line 76

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

#rectObject



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

def rect
  @connection.get "rect"
end

#screenshotObject



25
26
27
# File 'lib/webdriver/element.rb', line 25

def screenshot
  @connection.get "screenshot"
end

#selected?Boolean

checkbox

Returns:

  • (Boolean)


34
35
36
# File 'lib/webdriver/element.rb', line 34

def selected?
  @connection.get "selected"
end

#sizeObject



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

def size
  @connection.get "size"
end

#tagObject



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

def tag
  @connection.get "name"
end

#textObject



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

def text
  @connection.get "text"
end

#value!(value) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/webdriver/element.rb', line 49

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