Identifying Android UI elements

269 views
Skip to first unread message

Jeffrey Blaze

unread,
Aug 7, 2013, 7:50:56 PM8/7/13
to appium-...@googlegroups.com
I've got an Android UI element that looks like this in source:

                    "@enabled" : "true",
                    "@focusable" : "false",
                    "@index" : "0",
                    "@text" : "Your Rewards",
                    "@checkable" : "false",
                    "@package" : "com.kabam.sdk.sample",
                    "@scrollable" : "false",
                    "@class" : "android.widget.TextView",
                    "@password" : "false",
                    "@long-clickable" : "false",
                    "@bounds" : "[97,73][360,122]",
                    "@selected" : "false",
                    "@content-desc" : "",
                    "@clickable" : "false",
                    "@focused" : "false",
                    "@checked" : "false"

Appium Inspector finds it thusly:
wd.findElement(By.xpath("//list[1]/linear[1]/relative[1]/text[1]"))

This also works:
 wd.findElement(By.xpath("//list[1]/linear[1]/relative[1]/textView[1]"))
Note that getText() works correctly for these two.


As much as I like using paths, those won't suffice.  I have tried the following without success:
wd.findElement(By.xpath("//list[1]/linear[1]/relative[1]/text[@text='Your Rewards']"))
wd.findElement(By.xpath("//list[1]/linear[1]/relative[1]/textView[@text='Your Rewards']"))
wd.findElement(By.xpath("//list[1]/linear[1]/relative[1]/text[text()='Your Rewards']"))
wd.findElement(By.xpath("//list[1]/linear[1]/relative[1]/textView[text()='Your Rewards']"))
wd.findElement(By.xpath("//list[1]/linear[1]/relative[1]/text[@value='Your Rewards']"))
wd.findElement(By.xpath("//list[1]/linear[1]/relative[1]/textView[@value='Your Rewards']"))

Any ideas as to how to access that element based on its text value?  There is a table (iOS-centric) of type shortcuts in https://github.com/jaykz52/mechanic/blob/master/src/mechanic-core.js
that is generally useful for building Selenium locators, but it doesn't help me here.




Jonathan Lipps

unread,
Aug 7, 2013, 8:07:45 PM8/7/13
to Jeffrey Blaze, appium-...@googlegroups.com
Can you reproduce this at all in the ApiDemos test app?

I would have thought these two would have worked:

Jeffrey Blaze

unread,
Aug 7, 2013, 8:45:38 PM8/7/13
to Jonathan Lipps, appium-...@googlegroups.com
No, I haven't looked at that app.  I'll try it.

I did find out, though, that the UI element in question does not have its content-desc attribute populated.  If the use of content-desc is analogous to the use of the accessibility attribute in iOS land, elements without that attribute will not be accessible by the usual means.


bootstrap online

unread,
Aug 8, 2013, 9:17:44 AM8/8/13
to Jeffrey Blaze, Jonathan Lipps, appium-...@googlegroups.com
There's an Android method to find by text that works even without
content-desc. Using the appium_lib gem, you'd find this element with
text('Your Rewards')
> --
> 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.

Jeffrey Blaze

unread,
Aug 8, 2013, 2:09:05 PM8/8/13
to Jonathan Lipps, appium-...@googlegroups.com
I can't find the ApiDemos app.  In /test/functional/apidemos/findElement.js there is this reference to it:

../../../sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk")

but it is not there.  Nor can I find it anywhere else in the repo.



On Wed, Aug 7, 2013 at 5:07 PM, Jonathan Lipps <jli...@gmail.com> wrote:

Jeffrey Blaze

unread,
Aug 8, 2013, 2:29:40 PM8/8/13
to bootstrap online, Jonathan Lipps, appium-...@googlegroups.com
Thanks for that.  I installed the gem (by following instructions at https://github.com/appium/ruby_lib).  Now what? How do I make my Java program aware of the capability provided by the gem?  And then what would my driver.findElement call look like?


bootstrap online

unread,
Aug 8, 2013, 3:03:33 PM8/8/13
to Jeffrey Blaze, Jonathan Lipps, appium-...@googlegroups.com
The appium_lib gem is only for Ruby. You'd have to translate the
individual method to Java.
https://github.com/appium/ruby_lib/blob/master/lib/appium_lib/android/element/generic.rb#L70

I think we need an Appium lib for Java to make this easier for people.
The api demos apk is here.
https://github.com/appium/ruby_lib_android/blob/master/api.apk

On Thu, Aug 8, 2013 at 2:29 PM, Jeffrey Blaze
Reply all
Reply to author
Forward
0 new messages