2015-10-27 34 views
2

我試圖刷卡MobileElement但它給服務器端的錯誤。這可能是什麼原因?Appium 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

您還可以使用TouchAction類進行滑動。 – Gaurav

回答

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; 
} 
+0

你的代碼對我來說工作得很好,謝謝 – Divya

+0

wlc fine np .. :) – Rohith

+0

我寫了「向上滾動」的代碼,它在底部找到特定的字符串時結束。 我想知道是否有任何特定的方式來知道它的頁面結尾(沒有比較b/w元素等) – Divya

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(); 
+0

謝謝,這段代碼爲我工作 – Divya

+0

歡迎您:)我很高興我能幫上忙。 – Slavo

+0

@Divya,如果您發現答案有幫助 - 請接受。如果你不知道如何,請參考[遊覽](http://stackoverflow.com/tour)。 – Opal

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); 
相關問題