以上是带有属性的uiautomator对象查看器屏幕截图。我正在使用通过pip install uiautomator
安装的python包uiautomator。我试图通过UI自动对象访问三点设置按钮。我尝试使用https://github.com/xiaocong/uiautomator#handler
以下是代码和错误:
import uiautomator as uia
d = uia.device() #below all are my attempts
>>> d(resourceId="com.android.camera2:id/three_dots").clickable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/mode_options_toggle")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/mode_options_toggle").clickable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="id/mode_options_toggle")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/mode_options_toggle").clickable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/mode_options_toggle").clickable()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/mode_options_toggle", className="com.android.camera2")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/mode_options_toggle", className="com.android.camera2").clcik()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/mode_options_toggle", className="com.android.camera2").click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/mode_options_toggle", className="com.android.camera2").click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(package="com.android.camera2")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/progress_overlay")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/progress_overlay")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(resourceId="com.android.camera2:id/progress_overlay")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(className="android.view.View")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(className="android.view.View").child(className="android.widget.LinearLayout", resourceId="com.android.camera2:id/mode_options_toggle")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(className="android.view.View").child(className="android.widget.LinearLayout", resourceId="com.android.camera2:id/mode_options_toggle").click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(text="").info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d.info
{u'contentDescription': u'', u'checked': False, u'clickable': False, u'scrollable': False, u'text': u'', u'packageName': u'com.android.camera2', u'selected': False, u'enabled': True, u'bounds': {u'top': 0, u'left': 0, u'right': 1440, u'bottom': 2560}, u'className': u'android.widget.FrameLayout', u'focusable': False, u'focused': False, u'checkable': False, u'resourceName': None, u'longClickable': False, u'visibleBounds': {u'top': 0, u'left': 0, u'right': 1440, u'bottom': 2392}, u'childCount': 2}
>>> d(packageName=u'com.android.camera2).info
File "<stdin>", line 1
d(packageName=u'com.android.camera2).info
^
SyntaxError: EOL while scanning string literal
>>> d(packageName=u'com.android.camera2').info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(className=u'com.android.camera2').info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(className=u'com.android.camera2').info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(className=u'').info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(className=u'android.widget.FrameLayout').info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>> d(className="android.widget.FrameLayout").info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'AutomatorDeviceObject' object is not callable
>>>
在所有尝试之后,我仍然无法访问任何UI对象。请让我知道我在这里缺少什么?
答案 0 :(得分:2)
变化:
import uiautomator as uia
d = uia.device()
要:
import uiautomator as uia
d = uia.device
这可以解决您的问题。
这是因为你在变量中调用函数device()。所以“d”不是函数,而是使用函数来接收值。
当我们使用括号调用函数时,Python理解我们正在调用它并在变量“d”上使用此结果。这就是为什么你面对“对象不可调用”的原因,因为没有对象作为参数传递给“device()”。
当我们不使用括号时我们不调用函数,我们引用它,当我们调用它时参数将被传递。
希望它有所帮助!
答案 1 :(得分:1)
不是您的问题的解决方案,而是替代方案:使用AndroidViewClient/culebra您可以运行
culebra -uG -o camera-options.py
有了窗口,您可以点击选项点
立即查看结果
同时,将生成包含重现此操作的代码的脚本
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2017 Diego Torres Milano
Created on 2017-11-24 by Culebra v13.5.2
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
try:
sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient
TAG = 'CULEBRA'
_s = 5
_v = '--verbose' in sys.argv
kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
vc = ViewClient(device, serialno, **kwargs2)
#vc.dump(window='-1') # FIXME: seems not needed
vc.dump(window=-1)
vc.findViewWithContentDescriptionOrRaise(u'''Options''').touch()