有很多关于 1 指点击、滑动、双击的教程,但我找不到任何关于 2 指点击的教程。
我认为 w3c Actions 可能是 Selenium 构造,并且两根手指点击不是您在桌面浏览器中执行的操作...但我很惊讶我无法在网上找到有用的信息。
或者也许我找错了树?我所知道的是 TouchActions 已被弃用,我们似乎正在转向(返回)到 w3c。
1 根手指点击可能看起来像这样:
PointerInput finger01 = new PointerInput(PointerInput.Kind.TOUCH, "finger01");
PointerInput.PointerEventProperties pep = new PointerInput.PointerEventProperties();
java.time.Duration duration0 = java.time.Duration.ofMillis(0);
java.time.Duration duration100 = java.time.Duration.ofMillis(100);
PointerInput.Origin vp = PointerInput.Origin.viewport();
Sequence tapSeq = new Sequence(finger01, 1);
tapSeq.addAction(finger01.createPointerMove(duration0, vp, 300, 400));
tapSeq.addAction(finger01.createPointerDown(0, pep));
tapSeq.addAction(finger01.createPointerMove(duration100, vp, 300, 400));
tapSeq.addAction(finger01.createPointerUp(0, pep));
但是对于 2 根手指点击,我想我需要将
finger01
和 finger02
(此处未显示)添加到 Sequence
几个小时后,这就是我想到的:
int x1 = 100;
int y1 = 200;
int x2 = 100;
int y2 = 200;
java.time.Duration duration = java.time.Duration.ofMillis(250);
PointerInput.Origin vp = PointerInput.Origin.viewport();
PointerInput finger01 = new PointerInput(PointerInput.Kind.TOUCH, "finger01");
Sequence tapSeq01 = new Sequence(finger01, 1);
tapSeq01.addAction(finger01.createPointerMove(duration, vp, x1, y1));
tapSeq01.addAction(finger01.createPointerDown(0)); // button = 0 (left mouse button)
tapSeq01.addAction(finger01.createPointerMove(duration, vp, x1, y1));
tapSeq01.addAction(finger01.createPointerUp(0));
PointerInput finger02 = new PointerInput(PointerInput.Kind.TOUCH, "finger02");
Sequence tapSeq02 = new Sequence(finger02, 1);
tapSeq02.addAction(finger02.createPointerMove(duration, vp, x2, y2));
tapSeq02.addAction(finger02.createPointerDown(0));
tapSeq02.addAction(finger02.createPointerMove(duration, vp, x2, y2));
tapSeq02.addAction(finger02.createPointerUp(0));
driver.perform(Arrays.asList(tapSeq01, tapSeq02));