How to handle this seek bar


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

  1. How you make move? I move it like: Unable to use clickGesture
  2. Enable in developer options to show touches and coordinates on phone. This helps you to see where you touching and moving.

But touch actions i think not available with appium 2.0.1

use W3C code sent. also you can check https://www.thegreenreport.blog/articles/the-transition-from-touch-to-w3c-actions-in-selenium/the-transition-from-touch-to-w3c-actions-in-selenium.html

PS touch actions just deprecated on Selenium side :slight_smile: so did Appium and using w3c commands instead

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));

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));