title: calabash-android scroll to element
body: <p>I am writing some test cases for an android app using calabash-android.</p>
  
  <p>My first idea to find the elements was to just scroll down until the element is found like this:</p>
  
  <pre><code>Then /^I enter "([^\"]*)" into the input field with id "([^\"]*)"$/ do |text, id|
      q = query("EditText id:'#{id}'")
      while q.empty?
          scroll_down
          q = query("EditText id:'#{id}'")
      end
      enter_text("android.widget.EditText id:'#{id}'", text)
  end
  </code></pre>
  
  <p>However should the page change and I already scrolled past the element in this way, I won't find the element i'm searching for. So the second idea was to do the search in this way:</p>
  
  <pre><code>Then /^I enter "([^\"]*)" into the input field with id "([^\"]*)"$/ do |text, id|
      q = query("EditText id:'#{id}'")
      while q.empty?
          scroll_down
          q = query("EditText id:'#{id}'")
      end
      while q.empty?
          scroll_up
          q = query("EditText id:'#{id}'")
      end
      enter_text("android.widget.EditText id:'#{id}'", text)
  end
  </code></pre>
  
  <p>However I don't know how to check for the end of the page and i hope there is a better way to search for the element then to scroll down to the bottom of the page and then scroll up again.</p>
  
  <p>So my two questions are: is there a better option and, if not how, do I find out that I'm at the bottom/top of the page?</p>
  
  <p><strong>EDIT:</strong>
  Thanks for the reminder and i pretty much went with your idea jmoody.</p>
  
  <p>I'm going to do it this way:</p>
  
  <pre><code>Then /^I enter "([^\"]*)" into the input field with id "([^\"]*)"$/ do |text, id|
      q = query("EditText id:'#{id}'")
      counter = 0
      while q.empty?
          break if counter == 5
          scroll_down
          q = query("EditText id:'#{id}'")
          counter = counter + 1
      end
      if counter == 5
          fail("The button with the id:'#{id}' could not be found")
      else
          enter_text("EditText id:'#{id}'", text)
      end
  end
  </code></pre>