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.

Parameters:

  • value (String, Integer)

    the value to exactly match.

Returns:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 9

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 "#{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.

Parameters:

  • value (String)

    the value to match exactly

Returns:



62
63
64
65
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 62

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.

Parameters:

  • value (String) (defaults to: false)

    the value to search for

Returns:



30
31
32
33
34
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 30

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.

Parameters:

  • value (String)

    the value to match exactly

Returns:



70
71
72
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 70

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

#first_buttonButton

Find the first button.

Returns:



38
39
40
41
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 38

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.

Returns:



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/appium_lib/android/uiautomator2/element/button.rb', line 45

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 > 0
  image_button_index = tags(::Appium::Android::ImageButton).length
  image_button_index -= 1 if image_button_index > 0

  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