UIAutomator is for Android only.
With UI Automator I can scroll and find element\elements with text\text contains\id\text starts with.
Searching for element via UIAutomator allows to actually scroll view up/down to the searchable element. First of all, it is a search action, you can use it for scrolling if you have a scrollable view and know element inside of it. So it requires:
View with scrollable=true attribute.
Know element id, text, etc. to locate it.
Can’t use coordinates.
Fails if element is not found.
Not precise, stops scrolling as soon as element is found.
- MobileElement firstClickableEl = driver.findElement(MobileBy.AndroidUIAutomator(“new UiSelector().clickable(true)”))
- MobileElement elementInView = driver.findElement(MobileBy.AndroidUIAutomator(“new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text(“‘ + text + ‘”).instance(0))’)
driver.swipe is with x and y coordinates.
Actions API is used for different gestures like touch, tap, drag&drop, swipe, etc.
- no need to locate elements
- Can use both coordinates and elements
- More precise if you pass the right coordinates
public void swipeScreen() {
// final value depends on your app and could be greater
final int ANIMATION_TIME = 200; // ms
final int PRESS_TIME = 200; // ms
int edgeBorder = 10; // better avoid edges
PointOption pointOptionStart, pointOptionEnd;
// init screen variables
Dimension dims = driver.manage().window().getSize();
// init start point = center of screen
pointOptionStart = PointOption.point(dims.width / 2, dims.height / 2);
pointOptionEnd = PointOption.point(dims.width / 2, dims.height - edgeBorder);
TouchAction touch = new TouchAction(driver);
touch.press(pointOptionStart)
// a bit more reliable when we add small wait
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(PRESS_TIME)))
.moveTo(pointOptionEnd)
.release().perform();
}