java - 如何将 TouchAction 命令的 String[] 转换为 Point

标签 java arrays string appium coordinates

我有一个坐标字符串数组,其中数组中的每个字符串都分配给一个 int

String[] A = {"217, 423", "557, 408", "927, 393"};
Random B=new Random();
int randomCoord=B.nextInt(3);

我希望能够像这样将这些坐标插入到下面的命令中

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(A[randomCoord])).perform();

但是当我这样做时,我收到一条错误消息

The method point(Point) in the type PointOption is not applicable for the arguments (String)

所以我尝试将 String 转换为这样的 int

TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(Integer.parseInt(A[randomCoord]))).perform();

但是我收到了这个错误

The method point(int, int) in the type PointOption is not applicable for the arguments (int)

谁能帮帮我吗?我希望代码在每次运行代码时插入字符串数组中的一组随机坐标。

最佳答案

不确定如何没有得到 NumberFormatException..但您需要将 A 的随机索引解析为单独的整数

    String[] points = A[randomCoord].split(",");
    int x = Integer.parseInt(points[0].trim());
    int y = Integer.parseInt(points[1].trim());
    TouchAction touchAction = new TouchAction(driver);
    touchAction.tap(PointOption.point(x, y)).perform();

关于java - 如何将 TouchAction 命令的 String[] 转换为 Point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58242811/

相关文章:

java - 如何使用 Maven 自动化多个构建?

PHP mysql : inserting data from an array

java 字符串缓冲区声明

对本地 apache 服务器的 Java http 请求 - UnknownHostException

java - SQL 连接错误,凭据正确,所有权限和访问权限均正确

java - 如何修复名称错误: Java error in HecDSS Python Script

循环时无法比较数组上的字符串

javascript - 从第一个索引中按顺序删除数组 javascript 值

Excel - 如何从大列表中查找通配符字符串

javascript - 通过组合字符串和变量来创建新的 JavaScript 变量