即使参数'forceviewserveruse':为True,AVC也无法通过id查找视图,

时间:2014-04-15 05:43:57

标签: python-2.7 view androidviewclient

我正在尝试使用AndroidViewClient 5.1.1自动编写电子邮件。请找到以下代码:

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无法识别撰写视图。请帮忙

1 个答案:

答案 0 :(得分:0)

使用Android API> = 19和 AndroidViewClient > = 5.3.1的设备,您将能够获取View ID。

例如,如果您使用culebra自动生成脚本

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

然后,myscript.py将包含

#! /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")

请注意,这是由 AndroidViewClient 5.4.4 获得的,因为它修复了自动生成的脚本中的一些缩进问题。

视图由其ID之后创建的变量名称标识

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

另请注意使用--start-activity在脚本开头自动启动活动。