Get nested elements Android

661 views
Skip to first unread message

Ramon Cidade

unread,
Feb 24, 2014, 3:49:00 PM2/24/14
to appium-...@googlegroups.com
I'm having a lot dificulty locating elements by xpath on appium with android.
The app I'm testing have a ListView, the ListView have nested LinearLayout elements. Each one of those LinearLayout have TextView and ImageView nested in, something like:


 ListView
    1 - LinearLayout
                 - TextView - value A
                 - ImageView
    2 - LinearLayout
                 - TextView - value B
                 - ImageView
    3 - LinearLayout
                 - TextView - value C
                 - ImageView

By logic a xpath similar to "//ListView/LinearLayout[1]/TextView" should return the element with "A" in value, and a xpath like "//ListView/LinearLayout[2]/TextView" should return "B". But that doesn't work :(

Am I messing up at some point?

Thanks!

Satyajit Malugu

unread,
Feb 24, 2014, 4:57:23 PM2/24/14
to Ramon Cidade, appium-...@googlegroups.com
Quick guess, should the bolded below be 0 and 1?

February 24, 2014 at 12:49 PM
--
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.

Jonathan Lipps

unread,
Feb 24, 2014, 4:59:43 PM2/24/14
to Satyajit Malugu, Ramon Cidade, appium-...@googlegroups.com
Hilariously, XPath is 1-indexed

Ramon Cidade

unread,
Feb 25, 2014, 7:25:12 AM2/25/14
to appium-...@googlegroups.com, Satyajit Malugu, Ramon Cidade
So anyone can help me? I'm using the uiautomatorviewer to inspect elements... Am I writing this wrong? I really need a way to use this correctly

Thanks!

Aniket Gadre

unread,
Feb 25, 2014, 11:12:43 AM2/25/14
to Ramon Cidade, appium-...@googlegroups.com, satyajit malugu

Why don't you just fetch the collection of layouts and get one of them using index and then find its children

Driver. Findelements(by. Tagname("linear")) [0].findelement(by.tagname("textview"))

Just an example... Tagnames may vary

Jonathan Lipps

unread,
Feb 25, 2014, 1:14:15 PM2/25/14
to Aniket Gadre, Ramon Cidade, appium-...@googlegroups.com, satyajit malugu
Also, what if you try "//list/linear[1]/text"? I think if you use "LinearLayout" you might need to fully qualify it, e.g., "android.widget.LinearLayout"

Ramon Cidade

unread,
Feb 25, 2014, 1:16:49 PM2/25/14
to appium-...@googlegroups.com, Ramon Cidade, satyajit malugu
I guess I already have tried this, but I'll try anyway... seems that the tree of elements appium finds is diferent from the tree that uiautomator show... Thanks anyway guys, if doesn't work I post again.

Ramon Cidade

unread,
Feb 25, 2014, 1:19:26 PM2/25/14
to appium-...@googlegroups.com, Aniket Gadre, Ramon Cidade, satyajit malugu
I'll try locating this way... I guess I should use appium inspector even for android for better results?
Reply all
Reply to author
Forward
0 new messages