1

Python and UIAutomator

I have the following function:

class BasePage:
    def __init__(self, device):
        self.device = device


def click(self, resourceId=None, text=None, className = None, descriptionContains= None, index=None, description=None):
    self.device(
            resourceId=resourceId,
            text=text,
            className=className,
            descriptionContains= descriptionContains,
            index=index,
            description=description
        ).click()


if __name__ == "__main__":
    start = time.time()
    from uiautomator import Device
    d =Device('520a7f14b9')
    basepage = BasePage(d)
    basepage.click(text="Phone")
    basepage.device.press.home()
    print time.time() - start

Now, it is not always that the click function is passed with all the arguments. Sometimes I can click on the element only using the text, and some other times a combination of text + className.

The above, basepage.click(text="Phone") call will FAIL,

uiautomator.JsonRPCError: JsonRPC Error code: 0, Message: java.lang.IllegalArgumentException: className cannot be null

How can I call the basepage.click() functional only with text in this case.

anotherCoder
  • 712
  • 3
  • 11
  • 25

1 Answers1

1

You must change the code (className = None) for (className = " "), because you are passing a string value and not an integer value!

Booga Roo
  • 1,665
  • 1
  • 21
  • 30