如何使用 Java 在 UIAutomator 中使用 XY 坐标点击按钮?
How to tap on button using XY coordinates in UIAutomator with Java?
我有 Appium/Python :
//calculation max_height
//calculation of max_width
action = TouchAction(self.driver)
action.tap(None, max_width, max_height).release().perform()
我的目标是执行相同的操作,但在 Java 中使用 UIautomator 工具。我已经尝试了下一个脚本,但它不起作用。
UiObject appButton = new UiObject(new UiSelector());
appButton.click(int x, int y);
我的应用程序是在 Unity 中制作的,我没有任何定位器的辅助功能,所以我必须在屏幕上使用 XY 位置。
有人解决这个问题吗?
谢谢。
我的做法是使用 UIDevice
,而不是 UIObject
(UIObject 用于调用应用程序内的特定方法或操作,但 UIDevice 用于设备操作,例如单击 X/Y,或按下 back/home 按钮)
@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,从屏幕的左上角开始。
我有 Appium/Python :
//calculation max_height
//calculation of max_width
action = TouchAction(self.driver)
action.tap(None, max_width, max_height).release().perform()
我的目标是执行相同的操作,但在 Java 中使用 UIautomator 工具。我已经尝试了下一个脚本,但它不起作用。
UiObject appButton = new UiObject(new UiSelector());
appButton.click(int x, int y);
我的应用程序是在 Unity 中制作的,我没有任何定位器的辅助功能,所以我必须在屏幕上使用 XY 位置。
有人解决这个问题吗? 谢谢。
我的做法是使用 UIDevice
,而不是 UIObject
(UIObject 用于调用应用程序内的特定方法或操作,但 UIDevice 用于设备操作,例如单击 X/Y,或按下 back/home 按钮)
@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,从屏幕的左上角开始。