【发布时间】:2016-12-01 07:18:50
【问题描述】:
我正在尝试使用 Appium 1.6 在 iOS 10 上的特定元素上向左滑动以显示删除按钮。
Touch Action and Swipe 向左滑动的代码在 appium 1.4 中运行良好,但问题是在我们迁移到 appium 1.6 后才出现的。
非常感谢任何帮助
【问题讨论】:
-
能否请您分享您的代码以防万一您可以正常工作?我从一天开始就在苦苦挣扎,还没有运气。
我正在尝试使用 Appium 1.6 在 iOS 10 上的特定元素上向左滑动以显示删除按钮。
Touch Action and Swipe 向左滑动的代码在 appium 1.4 中运行良好,但问题是在我们迁移到 appium 1.6 后才出现的。
非常感谢任何帮助
【问题讨论】:
我遇到了同样的问题,现在我找到了解决方案。
详情:
Appium 1.6.4 beta
Java-Client-5.x beta
Appium 1.6.x - Swipe 已被移除,我们必须创建自己的 用于滑动的 TouchAction,在那个 waitAction() 使用负值将 执行快速滑动动作。例如 waitAction(-200)。
TouchAction action1 = new TouchAction(driver).press(x,y).waitAction(-200).moveTo(x_travel, y_travel).release();
action1.perform();
发表您的反馈。
【讨论】:
public void swipe(String direction, int offset, int time) {
int y = appiumDriver.manage().window().getSize().getHeight();
int x = appiumDriver.manage().window().getSize().getWidth();
TouchAction touchAction = new TouchAction(appiumDriver);
System.out.println(x+" "+y);
System.out.println("Entering swipe");
if("right".equalsIgnoreCase(direction))
{
System.out.println("Swipe Right");
touchAction.press(x-offset, y/2).moveTo(-(x-(2*offset)), 0).release().perform();
}else if("left".equalsIgnoreCase(direction)){
System.out.println("Swipe Left");
touchAction.press(offset, y/2).moveTo((x-(2*offset)), 0).release().perform();
}else if("up".equalsIgnoreCase(direction)){
System.out.println("Swipe Up");
touchAction.press(x/2, offset).moveTo(0, y-(2*offset)).release().perform();
}else if("down".equalsIgnoreCase(direction)){
System.out.println("Swipe Down");
touchAction.press(x/2, y-offset).moveTo(0, -(y-(2*offset))).release().perform();
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
【讨论】:
试试这个代码。调用 flick_left 并传递 WebElement。
flick_left(元素)
public void flick_left(WebElement flick_element) {
Point location = flick_element.getLocation();
Dimension size = flick_element.getSize();
int flick_x, flick_y, flick_start_x, flick_end_x,flick_start_y,flick_end_y;
flick_x =size.getWidth();
flick_y = location.y + (size.getHeight()/2);
flick_start_x = flick_x - (int)((double)flick_x*0.25);
flick_end_x = flick_x -(int)((double)flick_x*0.55);
swipe(flick_start_x, flick_y, flick_end_x, flick_y,-200);
}
public void swipe(int swipe_start_x, int swipe_start_y, int swipe_end_x, int swipe_end_y,int duration){
int x = swipe_start_x;
int y = swipe_start_y;
int x_travel = swipe_end_x-swipe_start_x;
int y_travel = swipe_end_y-swipe_start_y;
TouchAction action1 = new TouchAction(driver).press(x,y).waitAction(duration).moveTo(x_travel, y_travel).release();
action1.perform();
}
【讨论】: