gpt4 book ai didi

python uiautomator 类型错误 : 'AutomatorDeviceObject' object is not callable

转载 作者:行者123 更新时间:2023-11-30 22:25:43 25 4
gpt4 key购买 nike

Main Screen

Settings click

以上是带有属性的 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 对象。请让我知道我在这里缺少什么?

最佳答案

更改:

import uiautomator as uia
d = uia.device()

致:

import uiautomator as uia
d = uia.device

这应该可以解决您的问题。

发生这种情况是因为您在变量内调用函数 device() 。所以“d”不是一个函数,而是使用一个函数来接收一个值。

当我们使用括号调用函数时,Python 知道我们正在调用它并在变量“d”上使用此结果。这就是您面临“对象不可调用”的原因,因为没有对象作为参数传递给“device()”。

当我们不使用括号时,我们不会调用该函数,而是对其进行引用,并且在调用它时将传递参数。

希望对你有帮助!

关于python uiautomator 类型错误 : 'AutomatorDeviceObject' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47453715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com