Module: Appium::Android::Uiautomator2::Element

Defined in:
lib/appium_lib/android/uiautomator2/element.rb,
lib/appium_lib/android/uiautomator2/element/button.rb

Instance Method Summary collapse

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.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 23

def button(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 ArgumentError, "#{index} is not a valid index. Must be >= 1" if index <= 0

    result = find_elements :uiautomator, _button_visible_selectors(index: index)
    raise _no_such_element if result.empty?

    return result[value - 1]
  end

  elements = find_elements :uiautomator, _button_contains_string(value)
  raise_no_such_element_if_empty(elements)
end

#button_exact(value) ⇒ Button

Find the first button that exactly matches value.



76
77
78
79
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 76

def button_exact(value)
  elements = find_elements :uiautomator, _button_exact_string(value)
  raise_no_such_element_if_empty(elements)
end

#buttons(value = false) ⇒ Array<Button>

Find all buttons containing value. If value is omitted, all buttons are returned.



44
45
46
47
48
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 44

def buttons(value = false)
  return find_elements :uiautomator, _button_visible_selectors unless value

  find_elements :uiautomator, _button_contains_string(value)
end

#buttons_exact(value) ⇒ Array<Button>

Find all buttons that exactly match value.



84
85
86
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 84

def buttons_exact(value)
  find_elements :uiautomator, _button_exact_string(value)
end

#first_buttonButton

Find the first button.



52
53
54
55
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 52

def first_button
  elements = find_elements :uiautomator, _button_visible_selectors(button_index: 0, image_button_index: 0)
  raise_no_such_element_if_empty(elements)
end

#last_buttonButton

Find the last button.



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 59

def last_button
  # uiautomator index doesn't support last
  # and it's 0 indexed
  button_index = tags(::Appium::Android::Button).length
  button_index -= 1 if button_index.positive?
  image_button_index = tags(::Appium::Android::ImageButton).length
  image_button_index -= 1 if image_button_index.positive?

  elements = find_elements :uiautomator,
                           _button_visible_selectors(button_index: button_index,
                                                     image_button_index: image_button_index)
  raise_no_such_element_if_empty(elements)
end