AndroidViewClient:如何在触摸之前检查 "Id/Text/Image" 是否存在?
AndroidViewClient: How to check if "Id/Text/Image" exist before touch it?
如何在触摸之前检查 ID/Text 是否存在?
我正在尝试这样做:
# class=android.widget.ImageView
com_evernote___id_close = vc.findViewByIdOrRaise("com.evernote:id/close")
if not com_evernote___id_close:
vc.sleep(1)
else:
com_evernote___id_close.touch()
登录 Evernote 后。它有时会显示一些帮助信息。所以如果它退出我想关闭如果不继续执行脚本。
当它不存在时显示此错误:
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.0.10-py2.7.egg/com/dtmilano/android/viewclient.py", line 3352, in findViewByIdOrRaise
raise ViewNotFoundException("ID", viewId, root)
com.dtmilano.android.viewclient.ViewNotFoundException: Couldn't find View with ID='com.evernote:id/close' in tree with root=ROOT
如果您不想在未找到视图时引发异常,请使用 ViewClient.findViewById()
而不是 ViewClient.findViewByIdOrRaise()
。
然后检查返回值是否不是None
。就这么简单!
如何在触摸之前检查 ID/Text 是否存在?
我正在尝试这样做:
# class=android.widget.ImageView
com_evernote___id_close = vc.findViewByIdOrRaise("com.evernote:id/close")
if not com_evernote___id_close:
vc.sleep(1)
else:
com_evernote___id_close.touch()
登录 Evernote 后。它有时会显示一些帮助信息。所以如果它退出我想关闭如果不继续执行脚本。
当它不存在时显示此错误:
File "/usr/local/lib/python2.7/dist-packages/androidviewclient-11.0.10-py2.7.egg/com/dtmilano/android/viewclient.py", line 3352, in findViewByIdOrRaise
raise ViewNotFoundException("ID", viewId, root)
com.dtmilano.android.viewclient.ViewNotFoundException: Couldn't find View with ID='com.evernote:id/close' in tree with root=ROOT
如果您不想在未找到视图时引发异常,请使用 ViewClient.findViewById()
而不是 ViewClient.findViewByIdOrRaise()
。
然后检查返回值是否不是None
。就这么简单!