I got the coordinates but touch action is not working for me. please help
WebElement seekBar = driver.findElement(By.className("android.widget.ImageView"));
//Get start point of seek bar
int startX = seekBar.getLocation().getX();
System.out.println(startX);
//Get vertical location of seekbar
int startY = seekBar.getLocation().getY();
System.out.println(startY);
//Get end point of seek bar
int endX = seekBar.getSize().getWidth();
System.out.println(endX);
//set seekbar move to position
//endX * 0.9 means at 100% of seek bar width
int moveToXDirectionAt = (int) (endX * 0.5);
System.out.println("Moving seek bar at " + moveToXDirectionAt +"In X Direction");
I have written this code but after that touch actions are not working Please help
@Aleksei please look into this
But touch actions i think not available with appium 2.0.1
If the element declares support of progress setting in its accessibility properties (the standard progress bar control should have that out of the box) then it might be possible via sendKeys call. See https://github.com/appium/appium-uiautomator2-server/blob/c4251d67ded42bdd8ed2552f45c35e46a9009454/app/src/main/java/io/appium/uiautomator2/handler/SendKeysToElement.java#L111
Otherwise using gestures emulation would be the only way to make it to change the value.
@Aleksei I had used this code it is getting the coordinates but not moving it from the position
WebElement seekBar = driver.findElement(By.className("android.widget.ImageView"));
Point sourceLocation = seekBar.getLocation();
System.out.println(sourceLocation);
Dimension sourceSize = seekBar.getSize();
System.out.println(sourceSize);
int centerX = sourceLocation.getX() + sourceSize.getWidth() / 2;
System.out.println(centerX);
int centerY = sourceLocation.getY() + sourceSize.getHeight() / 2;
System.out.println(centerY);
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence tap = new Sequence(finger, 1);
tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), centerX, centerY));
tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(List.of(tap));
Demo_User:
tap.addAction(finger.createPointerMove(Duration.ofMillis(0), PointerInput.Origin.viewport(), centerX, centerY)); tap.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg())); tap.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg())); driver.perform(List.of(tap));
you missing one createPointerMove. plus I adding one more to follow more user behavior expected:
PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence tapSeq = new Sequence(finger, 1);
tapSeq.addAction(finger.createPointerMove(Duration.ofMillis(0),
PointerInput.Origin.viewport(), startX, startY));
tapSeq.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg()));
tapSeq.addAction(finger.createPointerMove(Duration.ofMillis(200),
PointerInput.Origin.viewport(), startX, startY));
tapSeq.addAction(finger.createPointerMove(Duration.ofMillis(200),
PointerInput.Origin.viewport(), startX, endY));
tapSeq.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));
driver.perform(Arrays.asList(tapSeq));