Find element by object id in Android

7,332 views
Skip to first unread message

satyajit malugu

unread,
May 1, 2013, 1:46:38 PM5/1/13
to appium-...@googlegroups.com
This is image from hierarchy viewer


I want to be able to find it by 'home'.

I tried find_element(:name, 'home') and find_element(:id, 'home'). This is using ruby bindings.

This is what is going through to appium
Pushing command to appium work queue: ["find",{"strategy":"name","selector":"home","context":"","multiple":false}]

I don't want to find by tag name and if possible avoid xpath. 

bootstrap online

unread,
May 1, 2013, 1:51:21 PM5/1/13
to satyajit malugu, appium-...@googlegroups.com
It's not possible to find elements by id when using uiautomator on Android. They're only accessible when using instrumentation. I'm working on a fix for this by preprocessing the APK to extract ids.


--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

image.png

bootstrap online

unread,
May 1, 2013, 1:54:40 PM5/1/13
to satyajit malugu, appium-...@googlegroups.com
I should mention the expected solution to this problem is attaching content descriptions to elements.
https://github.com/bootstraponline/android_content_description
image.png

satyajit malugu

unread,
May 1, 2013, 1:59:44 PM5/1/13
to bootstrap online, appium-...@googlegroups.com
That's very clever. Are you planning to use res/*.xml files for extracting these?

bootstrap online wrote:

I should mention the expected solution to this problem is attaching
content descriptions to elements.
https://github.com/bootstraponline/android_content_description


On Wed, May 1, 2013 at 1:51 PM, bootstrap online
<ma...@bootstraponline.com <mailto:ma...@bootstraponline.com>> wrote:

    It's not possible to find elements by id when using uiautomator on
    Android. They're only accessible when using instrumentation. I'm
    working on a fix for this by preprocessing the APK to extract ids.


    On Wed, May 1, 2013 at 1:46 PM, satyajit malugu <sa...@malugu.com
    <mailto:sa...@malugu.com>> wrote:

        This is image from hierarchy viewer


        I want to be able to find it by 'home'.

        I tried find_element(:name, 'home') and find_element(:id,
        'home'). This is using ruby bindings.

        This is what is going through to appium
        Pushing command to appium work queue:
        ["find",{"strategy":"name","selector":"home","context":"","multiple":false}]

        I don't want to find by tag name and if possible avoid xpath.

        --
        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

bootstrap online

unread,
May 1, 2013, 2:02:07 PM5/1/13
to satyajit malugu, appium-...@googlegroups.com
Yes. I'm currently using only res/strings.xml however I can easily support them all if there's a benefit.

satyajit malugu

unread,
May 1, 2013, 2:16:46 PM5/1/13
to bootstrap online, appium-...@googlegroups.com
I am not too familiar with strings.xml but in our app, we have several xml files under different folders rooted under res.
Drawable, color, layout etc..
Though I am not sure if we have any value munging all these files.

bootstrap online wrote:

Yes. I'm currently using only res/strings.xml however I can easily
support them all if there's a benefit.


On Wed, May 1, 2013 at 1:59 PM, satyajit malugu <sa...@malugu.com
<mailto:sa...@malugu.com>> wrote:

    That's very clever. Are you planning to use res/*.xml files for
    extracting these?

    bootstrap online wrote:


    I should mention the expected solution to this problem is attaching
    content descriptions to elements.
    https://github.com/bootstraponline/android_content_description


    On Wed, May 1, 2013 at 1:51 PM, bootstrap online
    <ma...@bootstraponline.com <mailto:ma...@bootstraponline.com>

    <mailto:ma...@bootstraponline.com>>> wrote:

        It's not possible to find elements by id when using
    uiautomator on
        Android. They're only accessible when using instrumentation. I'm
        working on a fix for this by preprocessing the APK to extract
    ids.


        On Wed, May 1, 2013 at 1:46 PM, satyajit malugu
    <sa...@malugu.com <mailto:sa...@malugu.com>
    <mailto:sa...@malugu.com <mailto:sa...@malugu.com>>> wrote:

            This is image from hierarchy viewer


            I want to be able to find it by 'home'.

            I tried find_element(:name, 'home') and find_element(:id,
    'home'). This is using ruby bindings.

            This is what is going through to appium
            Pushing command to appium work queue:
          
    ["find",{"strategy":"name","selector":"home","context":"","multiple":false}]

            I don't want to find by tag name and if possible avoid xpath.

            --
    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
    <mailto:appium-discuss%2Bunsu...@googlegroups.com>

bootstrap online

unread,
May 1, 2013, 2:18:27 PM5/1/13
to satyajit malugu, appium-...@googlegroups.com
I have those also however so far I only needed values from string.xml.


To unsubscribe from this group and stop receiving emails from it, send an email to appium-discus...@googlegroups.com.

bootstrap online

unread,
May 1, 2013, 2:38:26 PM5/1/13
to satyajit malugu, appium-...@googlegroups.com
I completed the gem. Let me know if it works for you.
https://github.com/bootstraponline/strings_from_apk_gem

Brian Hoffart

unread,
Jul 15, 2013, 11:38:09 AM7/15/13
to appium-...@googlegroups.com, satyajit malugu
Have you started the id from apk by chance? My app has mostly uses IDs and I need a way to located them directly. If any changes are made to the UI, xpath and tagnames might not work.


            Visit this group at
    http://groups.google.com/group/appium-discuss?hl=en.
            For more options, visit
    https://groups.google.com/groups/opt_out.



bootstrap online

unread,
Jul 15, 2013, 11:41:24 AM7/15/13
to Brian Hoffart, appium-...@googlegroups.com, satyajit malugu
This feature is now in Appium's server and it works well. There's no
need to use Ruby or have a gem installed.
>>>> <mailto:appium-discuss%252Buns...@googlegroups.com>>.
>>>>
>>>>
>>>> Visit this group at
>>>> http://groups.google.com/group/appium-discuss?hl=en.
>>>> For more options, visit
>>>> https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> 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?hl=en.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>
>>>
>>
> --
> 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.

Brian Hoffart

unread,
Jul 16, 2013, 9:55:26 AM7/16/13
to appium-...@googlegroups.com, Brian Hoffart, satyajit malugu
can you give me a quick example java code on it..? Id greatly appreciate it.
>>>>     <mailto:appium-discuss%252Bunsubscribe@googlegroups.com>>.

bootstrap online

unread,
Jul 16, 2013, 10:29:56 AM7/16/13
to Brian Hoffart, appium-...@googlegroups.com, satyajit malugu
The standard find by id will work in Java. The Ruby examples are here:
https://github.com/appium/ruby_lib_android/blob/master/lib/android/specs/android/helper.rb#L82
>> >>>> <mailto:appium-discuss%252Buns...@googlegroups.com>>.

Brian Hoffart

unread,
Jul 16, 2013, 11:27:25 AM7/16/13
to appium-...@googlegroups.com, Brian Hoffart, satyajit malugu
But it does not work. I want to be able to point to elements in the gen R.ID.java file of my android app. When I used driver.findElement(By.id("someID')); it pulls from R.String.java
>> >>>>     <mailto:appium-discuss%252Bunsubscribe@googlegroups.com>>.

bootstrap online

unread,
Jul 16, 2013, 11:42:35 AM7/16/13
to Brian Hoffart, appium-...@googlegroups.com, satyajit malugu
R.ID requires Selendroid.
http://dominikdary.github.io/selendroid/

On Tue, Jul 16, 2013 at 11:27 AM, Brian Hoffart
>> >> >>>> <mailto:appium-discuss%252Buns...@googlegroups.com>>.

Brian Hoffart

unread,
Jul 16, 2013, 11:44:37 AM7/16/13
to appium-...@googlegroups.com, Brian Hoffart, satyajit malugu
ahhhh. thank you
>> >> >>>>     <mailto:appium-discuss%252Bunsubscribe@googlegroups.com>>.

Brian Hoffart

unread,
Jul 16, 2013, 2:51:57 PM7/16/13
to appium-...@googlegroups.com, Brian Hoffart, satyajit malugu
did you mean selendroid by itself or that +appium?
>> >> >>>>     <mailto:appium-discuss%252Bunsubscribe@googlegroups.com>>.

bootstrap online

unread,
Jul 16, 2013, 3:03:27 PM7/16/13
to Brian Hoffart, appium-...@googlegroups.com, satyajit malugu
Appium uses Selendroid when the device is set to selendroid.
>> >> >> >>>> <mailto:appium-discuss%252Buns...@googlegroups.com>>.

Marius Bob

unread,
Jul 30, 2013, 6:20:09 AM7/30/13
to appium-...@googlegroups.com

So, how could be accessed the elements that have their IDs defined in the layout file?

For the ContactManager application I see that the “Add Contact” button has the ID addContactButton => so I want to perform a click by finding this ID and NOT the text on the button because the texts might change.

 

Is it possible? As I know this is possible with selendroid…but the button is not found when writing the test.

bootstrap online

unread,
Jul 30, 2013, 9:08:28 AM7/30/13
to Marius Bob, appium-...@googlegroups.com
Find by id works with selendroid.

Marius BoB

unread,
Jul 30, 2013, 9:34:36 AM7/30/13
to appium-...@googlegroups.com
Thank you for you support.
I've set the device to selendroid and now I have another error:


error: Error: Command failed: error: cannot bind to socket

info: Overriding session id with ,,,,,,,,,,,,,,,

error: Failed to start an Appium session, err was: Error: Command failed: error: cannot bind to socket

info: Responding to client with error: {"status":6,"value":{"message":"A session is either terminated or not started (Original error: Command failed: error: cannot bind to socket\n)","killed":false,"code":1,"signal":null,"origValue":"Command failed: error: cannot bind to socket\n"},"sessionId":null}
POST /wd/hub/session 500 8834ms - 307
info: Clearing out appium devices
info: Clearing out any previous sessions

bootstrap online

unread,
Jul 30, 2013, 9:37:07 AM7/30/13
to Marius BoB, appium-...@googlegroups.com
Another appium may be running. Try killall -9 node

Marius BoB

unread,
Jul 30, 2013, 10:34:29 AM7/30/13
to appium-...@googlegroups.com
nothing's changed.
the output after running the test is as follows:
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.26.0', revision: '18040', time: '2012-11-02 09:44:45'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.7.5', java.version: '1.7.0_25'
Driver info: driver.version: SelendroidDriver

the only thing that should be changed is app-device from Android to selendroid?

Should I instantiate the driver object as SelendroidDriver?

bootstrap online

unread,
Jul 30, 2013, 10:58:43 AM7/30/13
to Marius BoB, appium-...@googlegroups.com
On Tue, Jul 30, 2013 at 10:34 AM, Marius BoB <znu...@gmail.com> wrote:
>
> the only thing that should be changed is app-device from Android to
> selendroid?

I think so. It works for me so I'm not sure why it's failing on your system.

Dan Cuellar

unread,
Jul 30, 2013, 11:34:25 AM7/30/13
to appium-...@googlegroups.com, Marius BoB
Instantiate as RemoteWebDriver
Reply all
Reply to author
Forward
0 new messages