Display android List View contents in terminal using python and appium


#1

Continuing the discussion from How to scroll in Appium using python:
@Appium_Master

I am writing test cases to check the proper functioning of the Android Audio Recorder App.
In one such test case, I want my Python code to display the names of recordings in the terminal.

Eg:

  • Recording20.mp3
  • Recording19.mp3
  • Recording3.mp3
  • Recording2.mp3
  • Recording1.mp3
  • Recording0.mp3

All the TextView content has the same resource-id: text1

Below is the screenshot from UIAutomatorViewer

enter image description here

I am using Ubuntu 14.04.

I implemented scroll method :

i = 0         
while i <= 2:  
    for num in range(0,5):     
	    element1 = WebDriverWait(self.driver, 15).until(EC.presence_of_element_located((By.XPATH, '//android.widget.ListView/android.widget.TextView[@index= %d]' % num)))
		self.assertIsNotNone(element1)
		print element1.text
	element_to_tap = self.driver.find_element_by_xpath('//android.widget.ListView/android.widget.TextView[@index= 5]')
	element_to_drag_to = self.driver.find_element_by_xpath('//android.widget.ListView/android.widget.TextView[@index= 0]')
	self.driver.scroll(element_to_tap, element_to_drag_to)	
	i = i +1

Here, I am trying to display 5 list elements each time, before scrolling… I had 15 list elements right now.

Result I am getting now is :

Recording15.mp3
Recording14.mp3
Recording13.mp3
Recording12.mp3
Recording11.mp3
Recording6.mp3
Recording5.mp3
Recording4.mp3
Recording3.mp3
Recording2.mp3
Recording6.mp3
Recording5.mp3
Recording4.mp3
Recording3.mp3
Recording2.mp3
ok

Recordings in the middle are missing… It scrolls completely to the bottom…

  1. How can I find the total count of the android ListView contents ? It would be helpful if I could get a way to count those, in order to put as a condition in loops. It gets terminated, when condition becomes false.
    I searched a lot, but couldn’t find.

I am too close to the answer, yet too far…