Class: SparklingWatir::Element
- Inherits:
-
Object
- Object
- SparklingWatir::Element
- Includes:
- Waitable
- Defined in:
- lib/sparkling_watir/element.rb
Overview
This is a element in the native app context
Instance Attribute Summary collapse
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
-
#element ⇒ Object
Returns the value of attribute element.
-
#selector ⇒ Object
readonly
Returns the value of attribute selector.
Instance Method Summary collapse
- #attribute(attribute_name) ⇒ Object
- #bounds ⇒ Object
- #center ⇒ Object
- #coordinates ⇒ Object (also: #location)
- #enabled? ⇒ Boolean
- #exists? ⇒ Boolean (also: #exist?)
-
#initialize(driver = nil, selector = nil, element = nil) ⇒ Element
constructor
A new instance of Element.
- #present? ⇒ Boolean (also: #visible?)
- #size ⇒ Object
- #text ⇒ Object
- #wd ⇒ Object
Methods included from Waitable
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
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
10 11 12 |
# File 'lib/sparkling_watir/element.rb', line 10 def driver @driver end |
#element ⇒ Object
Returns the value of attribute element.
11 12 13 |
# File 'lib/sparkling_watir/element.rb', line 11 def element @element end |
#selector ⇒ Object (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 |
#bounds ⇒ Object
62 63 64 |
# File 'lib/sparkling_watir/element.rb', line 62 def bounds { x: coordinates.x + size.width, y: coordinates.y + size.height } end |
#center ⇒ Object
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 |
#coordinates ⇒ Object 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
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?
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?
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 |
#size ⇒ Object
57 58 59 60 |
# File 'lib/sparkling_watir/element.rb', line 57 def size assert_exists element&.size end |
#text ⇒ Object
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 |
#wd ⇒ Object
21 22 23 |
# File 'lib/sparkling_watir/element.rb', line 21 def wd element || locate end |