Module: Appium::Android::Espresso::Element
- Defined in:
- lib/appium_lib/android/espresso/element.rb,
lib/appium_lib/android/espresso/element/button.rb,
lib/appium_lib/android/espresso/element/generic.rb
Instance Method Summary collapse
-
#button(value) ⇒ Button
Find the first button that contains value or by index.
-
#button_exact(value) ⇒ Button
Find the first button that exactly matches value.
-
#buttons(value = false) ⇒ Array<Button>
Find all buttons containing value.
-
#buttons_exact(value) ⇒ Array<Button>
Find all buttons that exactly match value.
-
#first_button ⇒ Button
Find the first button.
-
#last_button ⇒ Button
Find the last button.
-
#scroll_to(text) ⇒ Element
Scroll to the first element containing target text or description.
-
#scroll_to_exact(text) ⇒ Element
Scroll to the first element with the exact target text or description.
Instance Method Details
#button(value) ⇒ Button
Find the first button that contains value or by index. If int then the button at that index is returned.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/appium_lib/android/espresso/element/button.rb', line 9 def (value) # Don't use ele_index because that only works on one element type. # Android needs to combine button and image button to match iOS. if value.is_a? Numeric index = value raise "#{index} is not a valid index. Must be >= 1" if index <= 0 # zero index (index: index - 1) end i = find_elements :xpath, (Button, value) e = find_elements :xpath, (ImageButton, value) raise_no_such_element_if_empty(i + e) (i + e)[0] end |
#button_exact(value) ⇒ Button
Find the first button that exactly matches value.
63 64 65 66 67 68 69 70 |
# File 'lib/appium_lib/android/espresso/element/button.rb', line 63 def (value) i = find_elements :xpath, (Button, value) e = find_elements :xpath, (ImageButton, value) raise_no_such_element_if_empty(i + e) (i + e)[0] end |
#buttons(value = false) ⇒ Array<Button>
Find all buttons containing value. If value is omitted, all buttons are returned.
32 33 34 35 36 37 38 |
# File 'lib/appium_lib/android/espresso/element/button.rb', line 32 def (value = false) return unless value i = find_elements :xpath, (Button, value) e = find_elements :xpath, (ImageButton, value) i + e end |
#buttons_exact(value) ⇒ Array<Button>
Find all buttons that exactly match value.
75 76 77 78 79 |
# File 'lib/appium_lib/android/espresso/element/button.rb', line 75 def (value) i = find_elements :xpath, (Button, value) e = find_elements :xpath, (ImageButton, value) i + e end |
#first_button ⇒ Button
Find the first button.
42 43 44 |
# File 'lib/appium_lib/android/espresso/element/button.rb', line 42 def (button_index: 0, image_button_index: 0) end |
#last_button ⇒ Button
Find the last button.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/appium_lib/android/espresso/element/button.rb', line 48 def # uiautomator index doesn't support last # and it's 0 indexed = (::Appium::Android::Button).length -= 1 if > 0 = (::Appium::Android::ImageButton).length -= 1 if > 0 (button_index: , image_button_index: ) end |
#scroll_to(text) ⇒ Element
Scroll to the first element containing target text or description. Scroll happens upto 30 times in centre of device width.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/appium_lib/android/espresso/element/generic.rb', line 9 def scroll_to(text) err = nil w_s = window_rect (1..30).each do |_count| begin action .move_to_location(w_s.width / 2, (w_s.height * 2) / 5) # pointer based magic number .pointer_down(:left) .move_to_location(0, w_s.height / 5) .release .perform sleep 1 # we must wait finish scrolling return text(text) rescue StandardError => e err = e end end raise err end |
#scroll_to_exact(text) ⇒ Element
Scroll to the first element with the exact target text or description. Scroll happens upto 30 times in centre of device width.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/appium_lib/android/espresso/element/generic.rb', line 36 def scroll_to_exact(text) err = nil w_s = window_rect (1..30).each do |_count| begin action .move_to_location(w_s.width / 2, (w_s.height * 2) / 5) # pointer based magic number .pointer_down(:left) .move_to_location(0, w_s.height / 5) .release .perform sleep 1 # we must wait finish scrolling return text_exact(text) rescue StandardError => e err = e end end raise err end |