title: Ruby/Appium: How to select element from find_elements array via text attribute
body: <p>So I use a general "I press "*" button" Gherkin statement for pressing buttons. My problem is the text is not standardized throughout the app.</p>
  
  <p>What I want to do is use find_elements to form an array of all button elements, take the text from my Gherkin input (for example: 'I press the "Yes" button'), utilize the .casecmp method to ignore the capitalization of my button text from the find_elements array and compare the text attributes and my Gherkin input.</p>
  
  <p>Here's my attempt at the code:</p>
  
  <pre><code>Then (/^I press the "([^"]*)" button$/) do |button_text|
  #assign gherkin input to variable
  @button_text = button_text
  #create find_elements array for all Buttons
  button_array = find_elements(xpath: "//android.widget.Button")
  #create for loop that will compare each element's text with @button_text
    button_array.each do |index|
     #Attempting to reference text attribute of array at index and compare @button_text with case insensitive comparison
  
     matching_button = button_array[index].text.casecmp("#{@button_text}")
       if matching_button = 0 #this means it's a match
        button_array[index].click()
       else
       end 
    end
  end
  </code></pre>
  
  <p>At the moment I get the following errors:</p>
  
  <pre><code>And I press the "YES" button                  # features/step_definitions_android/common_steps.rb:107
        no implicit conversion of Selenium::WebDriver::Element into Integer (TypeError)
        ./features/step_definitions_android/common_steps.rb:113:in `[]'
        ./features/step_definitions_android/common_steps.rb:113:in `block (2 levels) in &lt;top (required)&gt;'
        ./features/step_definitions_android/common_steps.rb:111:in `each'
        ./features/step_definitions_android/common_steps.rb:111:in `/^I press the "([^"]*)" button$/'
        features/FAB.feature:18:in `And I press the "YES" button'
  </code></pre>
  
  <p>I'm not totally sure what these errors mean in my case but I'm continuing my research. If anyone can share insight into what I'm doing incorrectly I'd greatly appreciate it.</p>
  
  <p>Also is there any documentation as to how appium stores elements in that array? Can I even compare the text attribute of the element to a variable or other value? Thanks a ton for any help you can give me.</p>