我有一个坐标字符串数组,其中数组中的每个字符串都分配给一个 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/