Working with Android ListView

1,891 views
Skip to first unread message

Princy G

unread,
Nov 28, 2013, 6:32:15 AM11/28/13
to appium-...@googlegroups.com

Hi,

                Can anybody guide me on how to work with Android Listview.  I want to identify the total no of items/options available in the listview.


As per the screenshot, my Listview has 8 options.

so I used the below code to print the total no of items/options available in the listview.

List<WebElement> items=driver.findElements(By.xpath("ListView"));
System.out.println(items.size());

But it prints '0' as a response.

Kindly help me on  this. Thanks in advance




Aniket Gadre

unread,
Nov 28, 2013, 8:41:01 AM11/28/13
to Princy G, appium-...@googlegroups.com
ListView is Tag Name not Xpath..  Find by Tag Name

Best Regards,
Aniket Gadre
 
Programming can be fun, so can cryptography; however they should not be combined.


--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Anil Kumar

unread,
Nov 29, 2013, 1:38:13 AM11/29/13
to appium-...@googlegroups.com
For counting items, you can use xpath //ListView/TextView
Message has been deleted

Princy G

unread,
Dec 2, 2013, 2:37:15 AM12/2/13
to appium-...@googlegroups.com

Thanks Aniket and Anil. Now I’m able to get the no of items in the list view but I’m facing one more issue in that

My Listview has 11 items, initially it shows only 7 items in the screen, we are able to see the remaining 4 items only when we scroll down the list,

So when we get the items count using size() method, it prints the response as ‘7’ instead of 11.  Kindly let me know how to resolve this  

Aniket Gadre

unread,
Dec 2, 2013, 3:33:00 AM12/2/13
to Princy G, appium-...@googlegroups.com
Its better to scroll through the list till end of list, pick up some unique text from each listview item , put it in an Array/List and then fetch it's count/size

Best Regards,
Aniket Gadre
 
Programming can be fun, so can cryptography; however they should not be combined.


--

Princy G

unread,
Dec 12, 2013, 1:01:49 AM12/12/13
to appium-...@googlegroups.com, Princy G
Hi Aniket,

Do you have any idea about how to detect that scroll has reached end of the list.

Thanks,
Princy.

STK

unread,
Feb 24, 2014, 5:44:09 AM2/24/14
to appium-...@googlegroups.com
I want to iterate through a list view in my project. Each cell is having a number of items in it like TextViews. For that i want to know the number of cells in the List view. I have tried the //ListView/LinearLayout. But it returns only one cell. Please help me to solve this.

Jonathan Lipps

unread,
Feb 24, 2014, 2:10:38 PM2/24/14
to STK, appium-...@googlegroups.com
In Android, elements in a ListView are not created until they're scrolled to. You'll need to scroll and periodically count the distinct new cells that appear. It's not easy to do, unfortunately.

On Feb 24, 2014, at 2:44 AM, STK <suve...@rapidvaluesolutions.com> wrote:

I want to iterate through a list view in my project. Each cell is having a number of items in it like TextViews. For that i want to know the number of cells in the List view. I have tried the //ListView/LinearLayout. But it returns only one cell. Please help me to solve this.

Satyajit Malugu

unread,
Feb 24, 2014, 5:00:25 PM2/24/14
to Jonathan Lipps, STK, appium-...@googlegroups.com
Using appium_lib I do a hack for scroll like this. This is slow but reasonably reliable.

def self.soft_scroll(text,scrolls=1)
    scrolls.to_i.times do
      begin
        scroll_to text unless exists { s_text text }
      rescue Selenium::WebDriver::Error::NoSuchElementError
      end
    end
  end

February 24, 2014 at 11:10 AM
In Android, elements in a ListView are not created until they're scrolled to. You'll need to scroll and periodically count the distinct new cells that appear. It's not easy to do, unfortunately.



--
http://appium.io
---
You received this message because you are subscribed to the Google Groups "Appium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.
Visit this group at http://groups.google.com/group/appium-discuss.
For more options, visit https://groups.google.com/groups/opt_out.
February 24, 2014 at 2:44 AM
Reply all
Reply to author
Forward
0 new messages