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('/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('/element/' + eid + '/accessibilityContainer')['value']
end

#attribute(name) ⇒ Object 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(name)
  client.get '/element/' + eid + '/attribute/' + name
end

#clearObject

Clearing text of an given element

Returns:

  • element uuid [String]



90
91
92
# File 'lib/wda_lib/element.rb', line 90

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

#clickObject

Tap on an element with its id

Returns:

  • element uuid [String]



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

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]



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

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

Parameters:

  • toX (String)

    , toY [String], duration [Double]



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

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



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

def eid
  @id['ELEMENT']
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


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

def location
  r = rect['value']
  Point.new(r['x'], r['y'])
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)


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

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

#send_keys(value) ⇒ Object

Set value to an element

Parameters:

  • value (String)

Returns:

  • element uuid [String]



78
79
80
# File 'lib/wda_lib/element.rb', line 78

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

#sizeStruct

Get element size

Returns:

  • (Struct)
    :width, :height


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

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]



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

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

#two_finger_tapObject

Two finger tap on an element with its id

Returns:

  • element uuid [String]



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

def two_finger_tap
  client.post '/uiaElement/' + 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