How to press a button twice using Google UiAutomator?

前端 未结 5 2005
日久生厌
日久生厌 2021-01-05 09:29

I have the following script for typing \'33\' into the Calculator, in Android, using UiAutomator. However, only the first \'3\' is accepted, the second press is entirely ig

5条回答
  •  再見小時候
    2021-01-05 09:48

    Instead of just searching by text, try searching by the text and the class. Here is a sample method for doing so.

    Uiobject getByTextAndClass(String text, String className) {
        return new UiObject(new UiSelector().text(text).className(className));
    }
    

    And then if you are trying to call this method for the Calculator button with number 3 on it:

    getByTextAndClass("3", android.widget.Button.class.getName()).click();
    

    You can use the UiAutomatorViewer tool: {android-sdk}/tools/uiautomator.bat to check the classnames and other attributes of different UiObjects.

    This works on my 4.2.2 devices, but I am downloading 4.1.2 to test it on there as well.

    I tried it on a 4.1.2 AVD and it works on my Windows machine.

提交回复
热议问题