I ended up taking the built in method, scroll_to and using dumbed down version of it called roll_to as seen below which I added in the common.rb file
def roll_to(query_string, options={})
options[:action] ||= lambda {}
all_query_string = query_string
#unless all_query_string.chomp.downcase.start_with?('all')
# all_query_string = "all #{all_query_string}"
#end
#wait_for_element_exists(all_query_string)
element = query(all_query_string).first
raise "No elements found. Query: #{all_query_string}" if element.nil?
element_y = element['rect']['y']
element_height = element['rect']['height']
element_bottom = element_y + element_height
scroll_view_query_string = options[:container] || if element.has_key?('html')
"android.webkit.WebView id:'#{element['webView']}'"
else
"#{all_query_string} parent android.widget.ScrollView index:0"
end
scroll_element = query(scroll_view_query_string).first
raise "Could not find parent scroll view. Query: '#{escape_quotes(scroll_view_query_string)}'" if scroll_element.nil?
scroll_element_y = scroll_element['rect']['y']
scroll_element_height = scroll_element['rect']['height']
if element_bottom > scroll_element_y + scroll_element_height
scroll_by_y = element_bottom - (scroll_element_y + scroll_element_height)
elsif element_y < scroll_element_y
scroll_by_y = element_y - scroll_element_y
else
scroll_by_y = 0
end
if scroll_by_y != 0
result = query(scroll_view_query_string, {scrollBy: [0, scroll_by_y]}).first
raise 'Could not scroll parent view' if result != '<VOID>'
end
=begin
visibility_query_string = all_query_string[4..-1]
action = { :action => lambda { touch visibility_query_string } }
opts = action.merge(opts = {})
wait_for_elements_exist([visibility_query_string], opts)
if opts[:action].parameters.length == 0
opts[:action].call
else
opts[:action].call(visibility_query_string)
end
=end
end
I used the above scroll_to method in the below definition
def go_to_identical_row(count, title, value)
value=value.to_s
mycount=numerizer(count).to_i
mytextbox="all TextView id:'titleView' text:'#{title}' parent LinearLayout id:'rowLayout' descendant * id:'textEntry' index:#{mycount}"
=begin
find_in_list(mytextbox, 'NonFocusingScrollView')
mycondition=query("TextView id:'titleView' text:'#{title}'", :text)
myarray=query("all TextView", :text)
indexlist=myarray.each_index.select{|i| myarray[i] == title}
indexvalue=indexlist[mycount]
until all_text(title)[mycount].length > 0
scroll("tableView", :down)
end
scroll_row="all TextView id:'titleView' text:'#{title}' index:#{mycount} parent android.widget.Scrollview index:0"
roll_to("all TextView text:'#{title}' parent LinearLayout id:'rowLayout' index:#{indexvalue}")
scroll_to("all TextView index:#{indexvalue}", action: lambda {|v| touch(v)})
=end
roll_to(mytextbox)
touch(mytextbox)
#mynewtextbox="all TextView id:'titleView' text:'#{title}' index:#{mycount}"
#mynewtextbox=mynewtextbox.each_index.select{|i| myarray[i] == title}
#query(mynewtextbox, setText:value)
query("TextView parent LinearLayout id:'rowLayout' descendant * id:'textEntry'", setText: value)
hide_soft_keyboard
#scroll_to_row
end
def numerizer(mynumber)
case mynumber
when 'first', '1st'
0
when 'second', '2nd'
1
when 'third', '3rd'
2
when 'fourth', '4th'
3
end
end
You can see where I commented out stuff that I was attempting to use before but failed pretty miserably.