# Finds and returns an element in a list even if the element is not on screen.
# You specify the element by the query parameter. The function scrolls down the list the element is found.
# If the element can't be found an empty array is returned
def find_in_list(query_string, list_view="android.widget.ListView")
query_result = query(query_string)
current_screen_state = query('*')
prev_screen_state = []
lv=query(list_view)
while (query_result.empty? and current_screen_state != prev_screen_state)
prev_screen_state = current_screen_state
if lv.empty?
scroll_down
else
scroll(list_view,:down) #perform_action('scroll_down')
end
query_result = query(query_string)
current_screen_state = query('*')
sleep 0.5
end
query_result = query(query_string)
current_screen_state = query('*')
prev_screen_state = []
while (query_result.empty? and current_screen_state != prev_screen_state)
prev_screen_state = current_screen_state
if lv.empty?
scroll_up
else
scroll(list_view,:up) #perform_action('scroll_down')
end
query_result = query(query_string)
current_screen_state = query('*')
sleep 0.5
end
query_result
end