我无法为Appium找到双击的实现,这很简单并且允许您传递元素定位器策略,所以这里:
public static void doubleTapElementBy(By by) {
WebElement el = getDriver().findElement(by);
MultiTouchAction multiTouch = new MultiTouchAction(getDriver());
TouchAction action0 = new TouchAction(getDriver()).tap(el).waitAction(50).tap(el);
try {
multiTouch.add(action0).perform();
} catch (WebDriverException e) {
logger.info("Unable to do second tap on element, probably because element requieres single tap on this Android version");
}
}
答案 0 :(得分:0)
这是伪代码的一种解决方法,并且可能有一种更“官方”的方法,但是如果没有其他解决方案,它应该可以工作:
Interpretmessages(){
switch(msg)
{
OnClick:
{ if (lastClicked - thisTime() < 0.2) //if it was clicked very recently
{doubleTapped()} //handle it as a double tap
else{lastClicked = thisTime()} //otherwise keep the time of the tap
} //end of OnClick
} //End of Message Handler
}//End of switch
}//End of messageHandler
如果您可以访问就绪计时器功能,则可以设置一个功能在点击熄灭后0.2秒执行:
OnClick: if (!functionWaiting) // has the timer not been set?
{
enableTimer(); // set a function to go off in x time
clicks = 0; //we'll tell it that there's been one click in a couple of lines
} //set it for the first click
clicks++; //if it's already clicked, it'll become 2 (double tap) otherwise it's just one
所以,这个想法是,当你得到一个水龙头时,你会检查最近是否有另一个(a。通过检查相对时间,b。通过检查功能是否仍处于待定状态)并依据它来处理它,请注意,您必须实现一个计时器,以便您的功能稍后触发,以便您有时间进行第二次点击
该风格借鉴了Win32的消息处理,我很确定它在那里有效,它也适用于你。
答案 1 :(得分:0)
双击并按住 - 使用以下代码:
new TouchAction(driver).press(112,567).release().perform().press(112,567).perform();
双击 - 使用以下代码:
new TouchAction(driver).press(112,567).release().perform().press(112,567).release().perform();
答案 2 :(得分:0)
您还可以尝试在TouchAction类中使用tap方法尝试以下方法。
TouchAction taction = new TouchAction(driver);
taction.tap(tapOptions().withElement(ElementOption.element(YOUR_WebElement))
.withTapsCount(2)).perform();
您还需要在静态导入下方添加:
import static io.appium.java_client.touch.TapOptions.tapOptions;