# frozen_string_literal: true # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. module Appium module Android module Espresso module Element # Find the first button that contains value or by index. # @param value [String, Integer] the value to exactly match. # If int then the button at that index is returned. # @return [Button] 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 # zero index _button_visible_selectors_xpath(index: index - 1) end i = find_elements :xpath, _button_contains_string_xpath(BUTTON, value) e = find_elements :xpath, _button_contains_string_xpath(IMAGE_BUTTON, value) raise_no_such_element_if_empty(i + e) (i + e)[0] end # Find all buttons containing value. # If value is omitted, all buttons are returned. # @param value [String] the value to search for # @return [Array