Class: WDA::Element

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

Instance Method Summary collapse

Constructor Details

#initialize(client, id) ⇒ Element



4
5
6
7
# File 'lib/wda_lib/element.rb', line 4

def initialize(client, id)
  @client = client
  @id = id
end

Instance Method Details

#accessible?Boolean

Check if element is accessible?



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

def accessible?
  client.get('/element/' + eid + '/accessible')['value']
end

#accessible_container?Boolean

Check if element is accessibilityContainer?



67
68
69
# File 'lib/wda_lib/element.rb', line 67

def accessible_container?
  client.get('/element/' + eid + '/accessibilityContainer')['value']
end

#attribute(name) ⇒ Object Also known as: []

Get attribute value



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

def attribute(name)
  client.get '/element/' + eid + '/attribute/' + name
end

#clearObject

Clearing text of an given element



95
96
97
# File 'lib/wda_lib/element.rb', line 95

def clear
  client.post '/element/' + eid + '/clear'
end

#clickObject

Tap on an element with its id



88
89
90
# File 'lib/wda_lib/element.rb', line 88

def click
  client.post '/element/' + eid + '/click'
end

#displayed?Boolean

Check if element is displayed?



53
54
55
# File 'lib/wda_lib/element.rb', line 53

def displayed?
  client.get('/element/' + eid + '/displayed')['value']
end

#double_tapObject

Double tap on an element with its id



102
103
104
# File 'lib/wda_lib/element.rb', line 102

def double_tap
  client.post '/uiaElement/' + eid + '/doubleTap'
end

#drag_to(toX, toY, duration = 0) ⇒ Object

Drag on an element with its id and position



129
130
131
132
133
# File 'lib/wda_lib/element.rb', line 129

def drag_to(toX, toY, duration = 0)
  fromX = location[:x]
  fromY = location[:y]
  client.post '/uiaTarget/' + eid + '/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: duration }
end

#eidObject



18
19
20
# File 'lib/wda_lib/element.rb', line 18

def eid
  @id['ELEMENT']
end

#enabled?Boolean

Check if element is enabled?



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

def enabled?
  client.get('/element/' + eid + '/enabled')['value']
end

#inspectObject

Remove useless attributes, return object only with element



10
11
12
# File 'lib/wda_lib/element.rb', line 10

def inspect
  format '#<%s:0x%x id=%s>', self.class, hash * 2, @id.inspect
end

#locationStruct

Get element size



144
145
146
147
# File 'lib/wda_lib/element.rb', line 144

def location
  r = rect['value']
  Point.new(r['x'], r['y'])
end

#nameObject

Get type from an element



74
75
76
# File 'lib/wda_lib/element.rb', line 74

def name
  client.get '/element/' + eid + '/name'
end

#rectObject

Get wdRect by id



32
33
34
# File 'lib/wda_lib/element.rb', line 32

def rect
  client.get '/element/' + eid + '/rect'
end

#refObject



14
15
16
# File 'lib/wda_lib/element.rb', line 14

def ref
  @id
end

#scroll(direction = nil) ⇒ Hash

Scroll on an element with its id



123
124
125
# File 'lib/wda_lib/element.rb', line 123

def scroll(direction = nil)
  client.post '/uiaElement/' + eid + '/scroll', { direction: direction }
end

#send_keys(value) ⇒ Object

Set value to an element



81
82
83
# File 'lib/wda_lib/element.rb', line 81

def send_keys(value)
  client.post '/element/' + eid + '/value', { value: value.chars }
end

#sizeStruct

Get element size



137
138
139
140
# File 'lib/wda_lib/element.rb', line 137

def size
  r = rect['value']
  Dimension.new(r['width'], r['height'])
end

#textObject

Get text from an element(StaticText or Button)



46
47
48
# File 'lib/wda_lib/element.rb', line 46

def text
  client.get '/element/' + eid + '/text'
end

#touch_hold(duration) ⇒ Object

Touch and hold on for a while finger tap on an element with its id



116
117
118
# File 'lib/wda_lib/element.rb', line 116

def touch_hold(duration)
  client.post '/uiaElement/' + eid + '/touchAndHold', { duration: duration }
end

#two_finger_tapObject

Two finger tap on an element with its id



109
110
111
# File 'lib/wda_lib/element.rb', line 109

def two_finger_tap
  client.post '/uiaElement/' + eid + '/twoFingerTap'
end