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

如何在Java的UIAutomator中使用XY坐标点击按钮?,java,android,ui-automation,android-uiautomator,Java,Android,Ui Automation,Android Uiautomator,我在Appium/Python中有: //calculation max_height //calculation of max_width action = TouchAction(self.driver) action.tap(None, max_width, max_height).release().perform() 我的目标是使用UIautomator工具在Java中执行相同的操作。我尝试了下一个脚本,但它不起作用 UiObject appButton = new UiObject

我在Appium/Python中有:

//calculation max_height
//calculation of max_width
action = TouchAction(self.driver)
action.tap(None, max_width, max_height).release().perform()
我的目标是使用UIautomator工具在Java中执行相同的操作。我尝试了下一个脚本,但它不起作用

UiObject appButton = new UiObject(new UiSelector());
appButton.click(int x, int y);
我的应用程序在Unity中制作,我没有任何定位器的可访问性,因此我必须在屏幕上使用XY位置

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

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


其中42是X,242是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);
    }
}