Question

i am trying to automate composing email using AndroidViewClient 5.1.1 . please find the code below :

kwargs1 = {'verbose': False, 'ignoresecuredevice': False}
kwargs3 = {'startviewserver': True, 'forceviewserveruse': True, 'autodump': False, 'ignoreuiautomatorkilled': True}
device1, serialno1 = ViewClient.connectToDeviceOrExit(serialno=device_id1, **kwargs1)
vc2 = ViewClient(device1, serialno1, **kwargs3)
vc2.dump()
device1.startActivity(component="com.android.email/com.android.email.activity.EmailActivity")
vc2.dump()
compose = vc2.findViewById('id/compose')
compose.touch()

AVC is unable to identify the compose view . please help

Was it helpful?

Solution

Using devices with Android API >= 19 and AndroidViewClient >= 5.3.1 you will be able to obtain the View ids.

For example, if you use culebra to auto-generate the script

$ culebra -VC --start-activity='com.google.android.email/com.android.email2.ui.MailActivityEmail' -o myscript.py

Then, myscript.py will contain

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013  Diego Torres Milano
Created on 2014-04-16 by Culebra v5.4.4

                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''


import re
import sys
import os

from com.dtmilano.android.viewclient import ViewClient


kwargs1 = {'verbose': True, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
device.startActivity(component='com.google.android.email/com.android.email2.ui.MailActivityEmail')
kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True}
vc = ViewClient(device, serialno, **kwargs2)
vc.dump(window='-1')


# class=android.widget.FrameLayout
no_id1 = vc.findViewByIdOrRaise("id/no_id/1")

# class=android.view.View
android___id_action_bar_overlay_layout = vc.findViewByIdOrRaise("android:id/action_bar_overlay_layout")

# class=android.widget.FrameLayout
android___id_action_bar_container = vc.findViewByIdOrRaise("android:id/action_bar_container")

# class=android.view.View
android___id_action_bar = vc.findViewByIdOrRaise("android:id/action_bar")

# class=android.widget.LinearLayout
no_id5 = vc.findViewByIdOrRaise("id/no_id/5")

# class=android.widget.FrameLayout
no_id6 = vc.findViewByIdOrRaise("id/no_id/6")

# class=android.widget.ImageView
android___id_up = vc.findViewByIdOrRaise("android:id/up")

# class=android.widget.ImageView
android___id_home = vc.findViewByIdOrRaise("android:id/home")

# class=android.widget.LinearLayout
no_id9 = vc.findViewByIdOrRaise("id/no_id/9")

# class=android.widget.TextView text=u'Inbox'
android___id_action_bar_title = vc.findViewByIdOrRaise("android:id/action_bar_title")

# class=android.widget.TextView text=u'999+ unread'
android___id_action_bar_subtitle = vc.findViewByIdOrRaise("android:id/action_bar_subtitle")

# class=android.widget.LinearLayout
no_id12 = vc.findViewByIdOrRaise("id/no_id/12")

# class=android.widget.TextView
com_android_email___id_compose = vc.findViewByIdOrRaise("com.android.email:id/compose")

# class=android.widget.TextView
com_android_email___id_search = vc.findViewByIdOrRaise("com.android.email:id/search")

# class=android.widget.ImageButton
no_id15 = vc.findViewByIdOrRaise("id/no_id/15")

# class=android.widget.FrameLayout
android___id_content = vc.findViewByIdOrRaise("android:id/content")

# class=android.view.View
no_id17 = vc.findViewByIdOrRaise("id/no_id/17")

# class=android.widget.FrameLayout
no_id18 = vc.findViewByIdOrRaise("id/no_id/18")

# class=android.widget.FrameLayout
com_android_email___id_content_pane = vc.findViewByIdOrRaise("com.android.email:id/content_pane")

# class=android.widget.RelativeLayout
com_android_email___id_between_chrome = vc.findViewByIdOrRaise("com.android.email:id/between_chrome")

# class=android.widget.FrameLayout
com_android_email___id_conversation_list = vc.findViewByIdOrRaise("com.android.email:id/conversation_list")

# class=android.widget.ListView
android___id_list = vc.findViewByIdOrRaise("android:id/list")

# class=android.widget.LinearLayout
no_id23 = vc.findViewByIdOrRaise("id/no_id/23")

# class=android.widget.LinearLayout
no_id24 = vc.findViewByIdOrRaise("id/no_id/24")

# class=android.widget.LinearLayout
com_android_email___id_nested_folder_container = vc.findViewByIdOrRaise("com.android.email:id/nested_folder_container")

# class=android.widget.RelativeLayout
no_id26 = vc.findViewByIdOrRaise("id/no_id/26")

# class=android.widget.ImageView
com_android_email___id_folder_imageView = vc.findViewByIdOrRaise("com.android.email:id/folder_imageView")

# class=android.widget.LinearLayout
com_android_email___id_text_layout = vc.findViewByIdOrRaise("com.android.email:id/text_layout")

# class=android.widget.TextView text=u'0'
com_android_email___id_count_textView = vc.findViewByIdOrRaise("com.android.email:id/count_textView")

# class=android.widget.LinearLayout
com_android_email___id_show_more_folders_row = vc.findViewByIdOrRaise("com.android.email:id/show_more_folders_row")

# class=android.widget.TextView text=u'Show 1 more folders'
com_android_email___id_show_more_folders_textView = vc.findViewByIdOrRaise("com.android.email:id/show_more_folders_textView")

# class=android.widget.TextView text=u'0'
com_android_email___id_show_more_folders_count_textView = vc.findViewByIdOrRaise("com.android.email:id/show_more_folders_count_textView")

# class=android.widget.FrameLayout
no_id34 = vc.findViewByIdOrRaise("id/no_id/34")

# class=android.view.View
no_id35 = vc.findViewByIdOrRaise("id/no_id/35")

# class=android.widget.FrameLayout
no_id36 = vc.findViewByIdOrRaise("id/no_id/36")

# class=android.view.View
no_id37 = vc.findViewByIdOrRaise("id/no_id/37")

# class=android.widget.FrameLayout
no_id38 = vc.findViewByIdOrRaise("id/no_id/38")

# class=android.view.View
no_id39 = vc.findViewByIdOrRaise("id/no_id/39")

# class=android.widget.FrameLayout
no_id40 = vc.findViewByIdOrRaise("id/no_id/40")

# class=android.view.View
no_id41 = vc.findViewByIdOrRaise("id/no_id/41")

# class=android.widget.FrameLayout
no_id42 = vc.findViewByIdOrRaise("id/no_id/42")

# class=android.view.View
no_id43 = vc.findViewByIdOrRaise("id/no_id/43")

# class=android.widget.FrameLayout
no_id44 = vc.findViewByIdOrRaise("id/no_id/44")

# class=android.view.View
no_id45 = vc.findViewByIdOrRaise("id/no_id/45")

Notice this has been obtained by AndroidViewClient 5.4.4 as it fixes some indentation problem in auto-generated scripts.

The Views are identified by the variable name created after their ids

com_android_email___id_compose = vc.findViewByIdOrRaise("com.android.email:id/compose")

Also notice the use of --start-activity to automatically start the Activity at the beginning of the script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top