java Appium tap(int x, int y) 函数似乎已被弃用。有替代品吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49048841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Appium tap(int x, int y) function seems to be deprecated. Any replacements?
提问by Sandeep Harisankar
I'm trying to automate an Android game and for that I'm using X,Y co-ordinates to make a button click, as identifying elements through ID, Xpath etc. is not possible for games. I'm using TouchAction tap(int x, int y) method (Appium Method) for achieving this. But unfortunately this method tap(int x, int y) seems to be deprecated. The other options replacing this looks to be --> touchAction.tap(PointOptions tapOptions) and touchAction.tap(TapOptions tapOptions). The same is the case with touchAction.press as well.
我正在尝试自动化 Android 游戏,为此我使用 X、Y 坐标进行按钮单击,因为游戏无法通过 ID、Xpath 等识别元素。我正在使用 TouchAction tap(int x, int y) 方法(Appium Method)来实现这一点。但不幸的是,这种方法 tap(int x, int y) 似乎已被弃用。替换它的其他选项看起来是 --> touchAction.tap(PointOptions tapOptions) 和 touchAction.tap(TapOptions tapOptions)。touchAction.press 也是如此。
My code to touch a specific button looks like this:
我触摸特定按钮的代码如下所示:
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(1280, 1013).perform();
Here, the X,Y values are found using Touch points in Android Device [Developer Options > Show pointer location]
在这里,X、Y 值是使用 Android 设备中的触摸点找到的 [开发者选项 > 显示指针位置]
Can anyone suggest a better way to achieve the same using non deprecated method? Thanks!
任何人都可以建议使用非弃用方法实现相同目标的更好方法吗?谢谢!
回答by Taryn
You can view the TouchAction documentation here:
您可以在此处查看 TouchAction 文档:
https://appium.github.io/java-client/io/appium/java_client/TouchAction.html
https://appium.github.io/java-client/io/appium/java_client/TouchAction.html
Here's the method that replaced the tap() you are using:
这是替换您正在使用的 tap() 的方法:
and here is the PointOption documentation, which is the new parameter to use with tap():
这是 PointOption 文档,这是与 tap() 一起使用的新参数:
https://appium.github.io/java-client/io/appium/java_client/touch/offset/PointOption.html
https://appium.github.io/java-client/io/appium/java_client/touch/offset/PointOption.html
So to answer your question, you have two choices with PointOption:
因此,要回答您的问题,PointOption 有两种选择:
- Using PointOption.point(x, y), which is a static instance of PointOption with those coordinate values
- 使用 PointOption.point(x, y),它是带有这些坐标值的 PointOption 的静态实例
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(1280, 1013)).perform()
- Using PointOption().withCoordinates(x, y), which returns a reference to the PointOption instance after setting those coordinate values
- 使用 PointOption().withCoordinates(x, y),它在设置这些坐标值后返回对 PointOption 实例的引用
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(new PointOption().withCoordinates(1280, 1013)).perform()
回答by Anuj Bansal
As different Options are introduced after an update , This will Work for you
由于更新后引入了不同的选项,这对您有用
new TouchAction(driver).tap(PointOption.point(x,y)).waitAction(waitOptions(Duration.ofMillis(duration))).moveTo(PointOption.point(x, y)).release().perform();
}
回答by Chuk Ultima
An alternative to the deprecated tap/press function is the 'longPress' function. Here's the function :
不推荐使用的点击/按下功能的替代方法是“longPress”功能。这是功能:
public T longPress(LongPressOptions longPressOptions) {
ActionParameter action = new ActionParameter("longPress", longPressOptions);
parameterBuilder.add(action);
//noinspection unchecked
return (T) this;
}
For more information, see : https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/TouchAction.java
有关更多信息,请参阅:https: //github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/TouchAction.java