例如:
1 # -*- coding:utf-8 -*- 2 from uiautomator import device as d 3 4 d(classname="android.widget.ListView", resourceId="android:id/list").click() 5 6 输出: 7 Traceback (most recent call last): 8 File "E:/Project/qqqq/13.py", line 4, in <module> 9 d(classname="android.widget.ListView", resourceId="android:id/list").click() 10 File "C:Python27libsite-packagesuiautomator-0.1.32-py2.7.egguiautomator\__init__.py", line 665, in __call__ 11 12 File "C:Python27libsite-packagesuiautomator-0.1.32-py2.7.egguiautomator\__init__.py", line 257, in __init__ 13 14 File "C:Python27libsite-packagesuiautomator-0.1.32-py2.7.egguiautomator\__init__.py", line 264, in __setitem__ 15 16 ReferenceError: classname is not allowed.
分析:
出现这种错误时一般都是实例的属性编写错误导致的,正确的应该是:className 实例属性的名字命名遵循规则为(如果只是一个单词,那首字母小写,如果是多个单词拼接,那从第二个单词开始的首字母大写如(aaBbCc),下面把uiautomator中所有实例属性key全部列出如下,不要再出错啦
1 class Selector(dict): 2 3 """The class is to build parameters for UiSelector passed to Android device. 4 """ 5 __fields = { 6 "text": (0x01, None), # MASK_TEXT, 7 "textContains": (0x02, None), # MASK_TEXTCONTAINS, 8 "textMatches": (0x04, None), # MASK_TEXTMATCHES, 9 "textStartsWith": (0x08, None), # MASK_TEXTSTARTSWITH, 10 "className": (0x10, None), # MASK_CLASSNAME 11 "classNameMatches": (0x20, None), # MASK_CLASSNAMEMATCHES 12 "description": (0x40, None), # MASK_DESCRIPTION 13 "descriptionContains": (0x80, None), # MASK_DESCRIPTIONCONTAINS 14 "descriptionMatches": (0x0100, None), # MASK_DESCRIPTIONMATCHES 15 "descriptionStartsWith": (0x0200, None), # MASK_DESCRIPTIONSTARTSWITH 16 "checkable": (0x0400, False), # MASK_CHECKABLE 17 "checked": (0x0800, False), # MASK_CHECKED 18 "clickable": (0x1000, False), # MASK_CLICKABLE 19 "longClickable": (0x2000, False), # MASK_LONGCLICKABLE, 20 "scrollable": (0x4000, False), # MASK_SCROLLABLE, 21 "enabled": (0x8000, False), # MASK_ENABLED, 22 "focusable": (0x010000, False), # MASK_FOCUSABLE, 23 "focused": (0x020000, False), # MASK_FOCUSED, 24 "selected": (0x040000, False), # MASK_SELECTED, 25 "packageName": (0x080000, None), # MASK_PACKAGENAME, 26 "packageNameMatches": (0x100000, None), # MASK_PACKAGENAMEMATCHES, 27 "resourceId": (0x200000, None), # MASK_RESOURCEID, 28 "resourceIdMatches": (0x400000, None), # MASK_RESOURCEIDMATCHES, 29 "index": (0x800000, 0), # MASK_INDEX, 30 "instance": (0x01000000, 0) # MASK_INSTANCE, 31 }