0

How can I check if exist an ID/Text before touch it?

I was trying with this:

# 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()

After LogIn on Evernote. It sometimes shows some help info. So if it exits I want to close if not the script continue executing.

And when it does not exist shows this error:

  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
CodeIK
  • 177
  • 1
  • 14

1 Answers1

1

If you don't want to raise an Exception if the View is not found then use ViewClient.findViewById() instead of ViewClient.findViewByIdOrRaise(). Then check if the returned values is not None. That simple!

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • I understood the difference between ViewClient.findViewById() and ViewClient.findViewByIdOrRaise(). Thanks! – CodeIK Jan 06 '16 at 15:41