1818@author: Diego Torres Milano
1919'''
2020
21- __version__ = '12.3 .0'
21+ __version__ = '12.4 .0'
2222
2323import json
2424import os
@@ -248,6 +248,12 @@ def findObject(self, **kwargs):
248248 if DEBUG :
249249 print >> sys .stderr , "UiAutomatorHelper: findObject: returning" , int (r [u'oid' ])
250250 return UiObject2 (self , int (r [u'oid' ]))
251+ elif r [u'status' ] == 'ERROR' :
252+ if DEBUG :
253+ print >> sys .stderr , "UiAutomatorHelper: findObject: returning" , int (r [u'oid' ])
254+ if r [u'statusCode' ] == - 1 :
255+ # Object not found
256+ return None
251257 raise RuntimeError ("Error: " + response )
252258
253259 def longClick (self , ** kwargs ):
@@ -324,6 +330,14 @@ def getText(self, uiObject=None, uiObject2=None):
324330 return r [u'text' ]
325331 raise RuntimeError ("Error: " + response )
326332
333+ def isChecked (self , uiObject = None ):
334+ # This path works for UiObject and UiObject2, so there's no need to handle both cases differently
335+ path = '/UiObject/%d/isChecked' % (uiObject .oid )
336+ response = self .__httpCommand (path , None )
337+ r = json .loads (response )
338+ if r [u'status' ] == 'OK' :
339+ return r [u'checked' ]
340+ raise RuntimeError ("Error: " + response )
327341
328342 #
329343 # UiScrollable
@@ -352,9 +366,16 @@ def uiScrollable(self, path, params = None):
352366
353367
354368class UiObject :
355- def __init__ (self , uiAutomatorHelper , oid ):
369+ def __init__ (self , uiAutomatorHelper , oid , response ):
356370 self .uiAutomatorHelper = uiAutomatorHelper
357371 self .oid = oid
372+ self .className = response ['className' ]
373+
374+ def getOid (self ):
375+ return self .oid
376+
377+ def getClassName (self ):
378+ return self .className
358379
359380 def click (self ):
360381 self .uiAutomatorHelper .click (oid = self .oid )
@@ -380,6 +401,12 @@ def click(self):
380401 def clickAndWait (self , eventCondition , timeout ):
381402 self .uiAutomatorHelper .clickAndWait (uiObject2 = self , eventCondition = eventCondition , timeout = timeout )
382403
404+ def isChecked (self ):
405+ """
406+
407+ :rtype: bool
408+ """
409+ return self .uiAutomatorHelper .isChecked (uiObject = self )
383410
384411 def longClick (self ):
385412 self .uiAutomatorHelper .longClick (oid = self .oid )
@@ -414,11 +441,11 @@ def flingToEnd(self, maxSwipes=20):
414441
415442 def getChildByDescription (self , uiSelector , description , allowScrollSearch ):
416443 oid , response = self .uiAutomatorHelper .uiScrollable (str (self .oid ) + '/getChildByDescription' , {'uiSelector' : uiSelector , 'contentDescription' : description , 'allowScrollSearch' : allowScrollSearch })
417- return UiObject (self .uiAutomatorHelper , oid )
444+ return UiObject (self .uiAutomatorHelper , oid , response )
418445
419446 def getChildByText (self , uiSelector , text , allowScrollSearch ):
420447 oid , response = self .uiAutomatorHelper .uiScrollable (str (self .oid ) + '/getChildByText' , {'uiSelector' : uiSelector , 'text' : text , 'allowScrollSearch' : allowScrollSearch })
421- return UiObject (self .uiAutomatorHelper , oid )
448+ return UiObject (self .uiAutomatorHelper , oid , response )
422449
423450 def setAsHorizontalList (self ):
424451 self .uiAutomatorHelper .uiScrollable (str (self .oid ) + '/setAsHorizontalList' )
0 commit comments