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.



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?

Parameters:

  • id (String)

    Element uuid

Returns:

  • (Boolean)

    is accessible? [String]



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

def accessible?
  client.get '/element/' + eid + '/accessible'
end

#accessible_container?Boolean

Check if element is accessibilityContainer?

Parameters:

  • id (String)

    Element uuid

Returns:

  • (Boolean)

    is accessibilityContainer? [String]



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

def accessible_container?
  client.get '/element/' + eid + '/accessibilityContainer'
end

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

Get attribute value

Parameters:

  • id (String)

    , name [String]



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

Parameters:

  • id (String)

    Element uuid

Returns:

  • element uuid [String]



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

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

#clickObject

Tap on an element with its id

Parameters:

  • id (String)

    Element uuid

Returns:

  • element uuid [String]



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

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

#displayed?Boolean

Check if element is displayed?

Parameters:

  • id (String)

    Element uuid

Returns:

  • (Boolean)


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

def displayed?
  client.get '/element/' + eid + '/displayed'
end

#double_tapObject

Double tap on an element with its id

Parameters:

  • id (String)

    Element uuid

Returns:

  • element uuid [String]



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

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:

  • to* (String)

    , duration [Double]



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

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?

Parameters:

  • id (String)

    Element uuid

Returns:

  • (Boolean)


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

def enabled?
  client.get '/element/' + eid + '/enabled'
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

Returns:

  • (Struct)
    :x, :y


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

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

#nameObject

Get type from an element

Parameters:

  • id (String)

    Element uuid



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

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

#rectObject

Get wdRect by id

Parameters:

  • id (String)

    Element uuid

Returns:

  • wdRect



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

Parameters:

  • id (String)

    , direction [String] up, down, left, right

Returns:

  • (Hash)


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

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

#send_keys(value) ⇒ Object

Set value to an element

Parameters:

  • id (String)

    Element uuid, 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


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

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

#textObject

Get text from an element(StaticText or Button)

Parameters:

  • id (String)

    Element uuid



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

Parameters:

  • id (String)

    , duration [Double]

Returns:

  • element uuid [String]



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

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

#two_finger_tapObject

Two finger tap on an element with its id

Parameters:

  • id (String)

    Element uuid

Returns:

  • element uuid [String]



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

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