class WDA::Element
Attributes
Public Class Methods
# File lib/wda_lib/element.rb, line 8 def initialize(client, id) @client = client @id = id end
Public Instance Methods
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
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
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
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
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
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 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 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 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
# File lib/wda_lib/element.rb, line 22 def eid @id['ELEMENT'] end
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
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
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
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
# File lib/wda_lib/element.rb, line 75 def name type end
Get wdRect by id @return is wdRect
# File lib/wda_lib/element.rb, line 34 def rect client.get('/element/' + eid + '/rect')['value'] end
# File lib/wda_lib/element.rb, line 18 def ref @id end
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
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
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
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 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 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
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