我正在尝试滑动MobileElement,但它给出了服务器端错误。这可能是什么原因?
代码:
MobileElement mb= (MobileElement)driver1.findElement(By.xpath("//android.widget.ListView[@index='0'][@resource-id='android:id/list']"));
mb.swipe(SwipeElementDirection.LEFT, 1000);
错误:
org.openqa.selenium.WebDriverException:未知的服务器端错误 处理命令时发生。 (警告:服务器没有 提供任何堆栈跟踪信息)命令持续时间或超时:16 毫秒
答案 0 :(得分:1)
尝试这个,这将有效:
TouchAction动作=新的TouchAction(驱动程序);
int startY2 = element1.getLocation().getY() + (element.getSize().getHeight() / 2);
int startX2 = element1.getLocation().getX() + (element.getSize().getWidth() / 2);
int endX2 = element2.getLocation().getX() + (element2.getSize().getWidth() / 2);
int endY2 = element2.getLocation().getY() + (element2.getSize().getHeight()/2) - (element2.getSize().getHeight()/2);
action.press(startX2, startY2).waitAction(2000).moveTo(endX2, endY2).release().perform();
答案 1 :(得分:0)
使用AppiumDriver可以更好地在基类中实现它
public void swipe(int startx, int starty, int endx, int endy, int duration)
将其命名为:
driver.swipe((int)screenWidth(), (int)screenHeight()*0.6), (int)screenWidth(), (int)screenHeight()*0.4), 0);
答案 2 :(得分:0)
您可以尝试使用这种代码安静的方式对所有移动设备进行动态刷卡:
Dimension dimension = driver.manage().window().getSize();
int width = dimension.getWidth();
int height = dimension.getHeight();
switch(direction)
{
case "right" : driver.swipe((int) (width*(0.20)), (int) (height*(0.50)), (int)(width*(0.80)), (int) (height*(0.50)), 6000);
break;
case "left" : driver.swipe((int) (width*(0.80)), (int) (height*(0.50)), (int) (width*(0.20)), (int) (height*(0.50)), 6000);
break;
case "up" : driver.swipe((int) (width*(0.50)), (int) (height*(0.70)), (int) (width*(0.50)), (int) (height*(0.30)), 6000);
break;
default : driver.swipe((int) (width*(0.50)), (int) (height*(0.30)), (int) (width*(0.50)), (int) (height*(0.70)), 6000);
break;
}