0

我正在尝试使用 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 无法识别撰写视图。请帮忙

4

1 回答 1

0

使用 Android API >= 19 和AndroidViewClient >= 5.3.1 的设备,您将能够获取视图 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在脚本开头使用 来自动启动 Activity。

于 2014-04-16T19:06:10.103 回答