Reputation: 25
I am using Appium For Automation this code using for swiping down but when I use it on the real device then it doesn't work. how to solve this for real devices.
Dimension dimension = driver.manage().window().getSize();
int start_x = (int) (dimension.width * 0.5);
int start_y = (int) (dimension.height * 0.8);
int end_x = (int) (dimension.width * 0.5);
int end_y = (int) (dimension.height * 0.2);
new TouchAction(driver).press(PointOption.point(start_x, start_y))
.waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2)))
.moveTo(PointOption.point(end_x, end_y)).release().perform();
Upvotes: 0
Views: 350
Reputation: 3658
If you want a reliable solution, you need to avoid using swipping based on screen dimensions, it is not 100% accurate even if you know the size.
Using AndroidUIAutomator locator you can scroll view up/down automatically right next to the search element, e.g. you know only text "Here it is":
MobileElement element = driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"Here it is\"))";
Personally, I strongly suggest not use text, but check resourceId
and className
in Android docs. Appium docs also has examples.
Upvotes: 1