I am trying to swipe MobileElement but its giving server-side error. What may be the cause here?
code :
MobileElement mb= (MobileElement)driver1.findElement(By.xpath("//android.widget.ListView[@index='0'][@resource-id='android:id/list']"));
mb.swipe(SwipeElementDirection.LEFT, 1000);
Error :
org.openqa.selenium.WebDriverException: An unknown server-side error
occurred while processing the command. (WARNING: The server did not
provide any stacktrace information) Command duration or timeout: 16
milliseconds
You can try with this peace of code for dynamic swipe for all the mobile devices:
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;
}
Try this one, this will work:
TouchAction action = new TouchAction(driver);
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();
Using AppiumDriver its better to implement this in your base class
public void swipe(int startx, int starty, int endx, int endy, int duration)
Call it as :
driver.swipe((int)screenWidth(), (int)screenHeight()*0.6), (int)screenWidth(), (int)screenHeight()*0.4), 0);