【问题标题】:How to tap on button using XY coordinates in UIAutomator with Java?如何在带有 Java 的 UIAutomator 中使用 XY 坐标点击按钮?
【发布时间】:2018-01-10 01:35:07
【问题描述】:

我在 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 位置。

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

【问题讨论】:

    标签: java android ui-automation android-uiautomator


    【解决方案1】:

    我的做法是使用UIDevice,而不是UIObject(UIObject 用于调用应用程序中的特定方法或操作,但 UIDevice 用于设备操作,例如单击 X/Y 或推回/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,从屏幕左上角开始。

    【讨论】:

    • 太棒了。太感谢了。工作。
    • 酷。将其标记为已接受,以便将来对其他人有所帮助
    猜你喜欢
    • 1970-01-01
    • 2015-08-27
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多