Class: SparklingWatir::Element

Inherits:
Object
  • Object
show all
Includes:
Waitable
Defined in:
lib/sparkling_watir/element.rb

Overview

This is a element in the native app context

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Waitable

#wait_until, #wait_while

Constructor Details

#initialize(driver = nil, selector = nil, element = nil) ⇒ Element

Returns a new instance of Element.



15
16
17
18
19
# File 'lib/sparkling_watir/element.rb', line 15

def initialize(driver = nil, selector = nil, element = nil)
  @driver = driver
  @selector = selector
  @element = element
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



10
11
12
# File 'lib/sparkling_watir/element.rb', line 10

def driver
  @driver
end

#elementObject

Returns the value of attribute element.



11
12
13
# File 'lib/sparkling_watir/element.rb', line 11

def element
  @element
end

#selectorObject (readonly)

Returns the value of attribute selector.



10
11
12
# File 'lib/sparkling_watir/element.rb', line 10

def selector
  @selector
end

Instance Method Details

#attribute(attribute_name) ⇒ Object



73
74
75
# File 'lib/sparkling_watir/element.rb', line 73

def attribute(attribute_name)
  wd.attribute(attribute_name)
end

#boundsObject



62
63
64
# File 'lib/sparkling_watir/element.rb', line 62

def bounds
  { x: coordinates.x + size.width, y: coordinates.y + size.height }
end

#centerObject



66
67
68
69
70
71
# File 'lib/sparkling_watir/element.rb', line 66

def center
  {
    x: coordinates[:x] + size.width / 2,
    y: coordinates[:y] + size.height / 2
  }
end

#coordinatesObject Also known as: location



50
51
52
53
# File 'lib/sparkling_watir/element.rb', line 50

def coordinates
  assert_exists
  element&.location
end

#enabled?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/sparkling_watir/element.rb', line 43

def enabled?
  assert_exists
  element&.enabled?
rescue Watir::Exception::UnknownObjectException
  false
end

#exists?Boolean Also known as: exist?

Returns:

  • (Boolean)


25
26
27
28
29
30
# File 'lib/sparkling_watir/element.rb', line 25

def exists?
  assert_exists
  true
rescue Watir::Exception::UnknownObjectException
  false
end

#present?Boolean Also known as: visible?

Returns:

  • (Boolean)


34
35
36
37
38
39
# File 'lib/sparkling_watir/element.rb', line 34

def present?
  assert_exists
  element&.displayed?
rescue Watir::Exception::UnknownObjectException
  false
end

#sizeObject



57
58
59
60
# File 'lib/sparkling_watir/element.rb', line 57

def size
  assert_exists
  element&.size
end

#textObject



77
78
79
80
81
82
83
# File 'lib/sparkling_watir/element.rb', line 77

def text
  if driver.capabilities[:platform_name] == 'Android'
    attribute('text')
  else
    attribute('label')
  end
end

#wdObject



21
22
23
# File 'lib/sparkling_watir/element.rb', line 21

def wd
  element || locate
end