如何使用UIAutomator中的XY坐标点击按钮?

时间:2017-08-02 17:28:36

标签: java android ui-automation uiautomator

我有Appium / Python:

id

我的目标是执行相同的操作,但是在Java中使用UIautomator工具。我已经尝试了下一个脚本,但它不起作用。

//calculation max_height
//calculation of max_width
action = TouchAction(self.driver)
action.tap(None, max_width, max_height).release().perform()

我的应用程序在Unity中制作,我没有任何定位器的可访问性,所以我必须在屏幕上使用XY位置。

有人解决了这个问题吗? 谢谢。

1 个答案:

答案 0 :(得分:1)

我这样做的方式是使用UIDevice,而不是UIObject(UIObject用于调用应用程序中的特定方法或操作,但UIDevice适用于设备,例如点击X / Y,或按后/主页按钮)

@RunWith(AndroidJUnit4.class)
public class SomeClass {
.... some setup and stuff...

    @Test
    public void testCoordinates() {
        UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        device.click(42, 242);
    }
}

其中42是X,242是Y,从屏幕的左上角开始。