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

Returns a new instance of Element.



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

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

Instance Method Details

#accessible?Boolean

Check if element is accessible?

Returns:

  • (Boolean)

    is accessible? [Boolean]



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

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

#accessible_container?Boolean

Check if element is accessibilityContainer?

Returns:

  • (Boolean)

    is accessibilityContainer? [Boolean]



65
66
67
# File 'lib/wda_lib/element.rb', line 65

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

#attributeObject Also known as: []

Get attribute value

Parameters:

  • name (String)

Returns:

  • is attributeValue [String]



41
42
43
# File 'lib/wda_lib/element.rb', line 41

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

#clearObject

Clearing text of an given element

Returns:

  • element uuid [String]



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

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

#clickObject

Tap on an element with its id

Returns:

  • element uuid [String]



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?

Returns:

  • (Boolean)

    is isVisible? [Boolean]



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

Returns:

  • element uuid [String]



114
115
116
# File 'lib/wda_lib/element.rb', line 114

def double_tap
  client.post '/wda/element/' + eid + '/doubleTap'
end

#drag_element_from_to(fromX, toX, fromY, toY, duration = 0) ⇒ Object

Drag on an element with its id and position

Parameters:

  • fromX (Double)

    , toX [Double], fromY [Double], toY [Double], duration [Double]



140
141
142
# File 'lib/wda_lib/element.rb', line 140

def drag_element_from_to(fromX, toX, fromY, toY, duration = 0)
  client.post '/wda/element/' + eid + '/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: duration }
end

#drag_from_to(fromX, toX, fromY, toY, duration = 0) ⇒ Object

Drag from a position to another position

Parameters:

  • fromX (Double)

    , toX [Double], fromY [Double], toY [Double], duration [Double]



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

def drag_from_to(fromX, toX, fromY, toY, duration = 0)
  client.post '/wda/dragfromtoforduration', { fromX: fromX, toX: toX, fromY: fromY, toY: toY, duration: duration }
end

#eidObject



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

def eid
  @id['ELEMENT']
end

#elswipe(scale, velocity) ⇒ Object

Element pinch

Parameters:

  • scale (Double)

    , velocity [Double]

Returns:

  • element uuid [String]



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

def elswipe(direction)
  client.post('/wda/element/' + eid + '/swipe', { direction: direction })
end

#enabled?Boolean

Check if element is enabled?

Returns:

  • (Boolean)

    is isEnabled? [Boolean]



28
29
30
# File 'lib/wda_lib/element.rb', line 28

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

#inspectObject

Remove useless attributes, return object only with element



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

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

#locationStruct

Get element size

Returns:

  • (Struct)
    :x, :y


159
160
161
162
# File 'lib/wda_lib/element.rb', line 159

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

#nameObject



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

def name
  type
end

#rectObject

Get wdRect by id

Returns:

  • is wdRect



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

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

#refObject



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

def ref
  @id
end

#scroll(direction = nil) ⇒ Hash

Scroll on an element with its id

Parameters:

  • direction (String) (defaults to: nil)

    up, down, left, right

Returns:

  • (Hash)


134
135
136
# File 'lib/wda_lib/element.rb', line 134

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

#send_keys(value) ⇒ Object

Set value to an element

Parameters:

  • value (String)

Returns:

  • element uuid [String]



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

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

#sizeStruct

Get element size

Returns:

  • (Struct)
    :width, :height


152
153
154
155
# File 'lib/wda_lib/element.rb', line 152

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

#textObject

Get text from an element(StaticText or Button)

Returns:

  • is text [String]



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

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

#touch_hold(duration) ⇒ Object

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

Parameters:

  • duration (Double)

Returns:

  • element uuid [String]



127
128
129
# File 'lib/wda_lib/element.rb', line 127

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

#two_finger_tapObject

Two finger tap on an element with its id

Returns:

  • element uuid [String]



120
121
122
# File 'lib/wda_lib/element.rb', line 120

def two_finger_tap
  client.post '/wda/element/' + eid + '/twoFingerTap'
end

#typeObject

Get type from an element, ex: type => “Icon”(XCUIElementTypeIcon)

Returns:

  • is type [String]



71
72
73
# File 'lib/wda_lib/element.rb', line 71

def type
  client.get('/element/' + eid + '/name')['value']
end