使用UIAutomator和Python的页面对象模型

时间:2018-09-18 22:25:46

标签: python ui-automation uiautomator

Python和UIAutomator

我具有以下功能:

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

现在,不总是将click函数与所有参数一起传递。有时,我只能使用文本单击元素,而有时只能使用文本+ className的组合。

以上,     basepage.click(text =“ Phone”) 呼叫将失败,

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

在这种情况下,如何仅使用文本调用basepage.click()函数。

1 个答案:

答案 0 :(得分:0)

您必须将代码(className = None)更改为(className = " "),因为您传递的是字符串值而不是整数值!