class WDA::Element

Attributes

client[R]

Public Class Methods

new(client, id) click to toggle source
# File lib/wda_lib/element.rb, line 8
def initialize(client, id)
  @client = client
  @id = id
end

Public Instance Methods

[]()
Alias for: attribute
accessible?() click to toggle source

Check if element is accessible? @return is accessible? [Boolean]

# File lib/wda_lib/element.rb, line 59
def accessible?
  client.get('/wda/element/' + eid + '/accessible')['value']
end
accessible_container?() click to toggle source

Check if element is accessibilityContainer? @return is accessibilityContainer? [Boolean]

# File lib/wda_lib/element.rb, line 65
def accessible_container?
  client.get('/wda/element/' + eid + '/accessibilityContainer')['value']
end
attribute() click to toggle source

Get attribute value @param name [String] @return is attributeValue [String]

# File lib/wda_lib/element.rb, line 41
def attribute
  client.get '/element/' + eid + '/attribute/name'
end
Also aliased as: []
clear() click to toggle source

Clearing text of an given element @return element uuid [String]

# File lib/wda_lib/element.rb, line 94
def clear
  client.post '/element/' + eid + '/clear'
end
click() click to toggle source

Tap on an element with its id @return element uuid [String]

# File lib/wda_lib/element.rb, line 88
def click
  client.post '/element/' + eid + '/click'
end
displayed?() click to toggle source

Check if element is displayed? @return is isVisible? [Boolean]

# File lib/wda_lib/element.rb, line 53
def displayed?
  client.get('/element/' + eid + '/displayed')['value']
end
double_tap() click to toggle source

Double tap on an element with its id @return element uuid [String]

# 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) click to toggle source

Drag on an element with its id and position @param fromX [Double], toX [Double], fromY [Double], toY [Double], duration [Double]

# 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) click to toggle source

Drag from a position to another position @param fromX [Double], toX [Double], fromY [Double], toY [Double], duration [Double]

# 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
eid() click to toggle source
# File lib/wda_lib/element.rb, line 22
def eid
  @id['ELEMENT']
end
elswipe(direction) click to toggle source

Element swipe @param direction [String] up, down, left, right @return element uuid [String]

# File lib/wda_lib/element.rb, line 101
def elswipe(direction)
  client.post('/wda/element/' + eid + '/swipe', { direction: direction })
end
enabled?() click to toggle source

Check if element is enabled? @return is isEnabled? [Boolean]

# File lib/wda_lib/element.rb, line 28
def enabled?
  client.get('/element/' + eid + '/enabled')['value']
end
inspect() click to toggle source

Remove useless attributes, return object only with element

# File lib/wda_lib/element.rb, line 14
def inspect
  format '#<%s:0x%x id=%s>', self.class, hash * 2, @id.inspect
end
location() click to toggle source

Get element size @return [Struct] [:x, :y]

# File lib/wda_lib/element.rb, line 159
def location
  r = rect
  Point.new(r['x'], r['y'])
end
name() click to toggle source
# File lib/wda_lib/element.rb, line 75
def name
  type
end
rect() click to toggle source

Get wdRect by id @return is wdRect

# File lib/wda_lib/element.rb, line 34
def rect
  client.get('/element/' + eid + '/rect')['value']
end
ref() click to toggle source
# File lib/wda_lib/element.rb, line 18
def ref
  @id
end
scroll(direction = nil) click to toggle source

Scroll on an element with its id @param direction [String] up, down, left, right @return [Hash]

# File lib/wda_lib/element.rb, line 134
def scroll(direction = nil)
  client.post '/wda/element/' + eid + '/scroll', { direction: direction }
end
send_keys(value) click to toggle source

Set value to an element @param value [String] @return element uuid [String]

# File lib/wda_lib/element.rb, line 82
def send_keys(value)
  client.post '/element/' + eid + '/value', { value: value.chars }
end
size() click to toggle source

Get element size @return [Struct] [:width, :height]

# File lib/wda_lib/element.rb, line 152
def size
  r = rect['value']
  Dimension.new(r['width'], r['height'])
end
text() click to toggle source

Get text from an element(StaticText or Button) @return is text [String]

# File lib/wda_lib/element.rb, line 47
def text
  client.get('/element/' + eid + '/text')['value']
end
touch_hold(duration) click to toggle source

Touch and hold on for a while finger tap on an element with its id @param duration [Double] @return element uuid [String]

# File lib/wda_lib/element.rb, line 127
def touch_hold(duration)
  client.post '/wda/element/' + eid + '/touchAndHold', { duration: duration }
end
two_finger_tap() click to toggle source

Two finger tap on an element with its id @return element uuid [String]

# File lib/wda_lib/element.rb, line 120
def two_finger_tap
  client.post '/wda/element/' + eid + '/twoFingerTap'
end
type() click to toggle source

Get type from an element, ex: type => “Icon”(XCUIElementTypeIcon) @return is type [String]

# File lib/wda_lib/element.rb, line 71
def type
  client.get('/element/' + eid + '/name')['value']
end