Search code examples
androidpython-2.7mobileandroidviewclient

AndroidViewClient View Checkbox isChecked()


I can use Culebra to touch the checkbox of Mobile data, make a checking True or False by calling checkbox_id.isChecked(), everything is working fine. But I can't find the method isChecked() in the script ViewClient.py, where does this method come from ?


Solution

  • If you take a look at View.__getattr__(), you'll see

       if self.map.has_key(name):
            ...
       elif name.startswith('is'):
            # try removing 'is' prefix
            if DEBUG_GETATTR:
                print >> sys.stderr, "    __getattr__: trying without 'is' prefix"
            suffix = name[2:].lower()
            if self.map.has_key(suffix):
                r = self.map[suffix]
            else:
                # Default behavior
                raise AttributeError, name
    

    So, when you invoke isChecked() on a View instance, 'is' prefix is removed and the remaining string is converted to lowercase and then self.map is checked to verify if it contains such key.