0

I am using TouchActions class in Appium to press and move the slider to a specified position.The problem that I am facing is that on some pages the slider works fine and I'm able to initiate touch action and move the slider, but on the other page the same thing may or may not work.What's uncanny is that the code seems to be working fine and no error is being thrown.It would be really helpful if someone points out what could possibly cause this behavior.

My code for controlling the slider is as follows:

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.TouchAction;
import org.openqa.selenium.WebElement;

public class SlideController {

private WebElement seekbar;
private AppiumDriver driver;
private TouchAction touchAction;
private final int offset = 200;

public SlideController(WebElement seekbar, AppiumDriver driver) {
    this.seekbar = seekbar;
    this.driver = driver;
}

public void slideBy(int slideByPercentage){
    int xStartingPoint = seekbar.getLocation().getX();
    int xEndingPoint = seekbar.getSize().getWidth();
    int yStartingAndEndingPoint = seekbar.getLocation().getY();
    moveSliderAccordingToSpecifiedPercentage(xStartingPoint,xEndingPoint,yStartingAndEndingPoint,slideByPercentage);
}

private void moveSliderAccordingToSpecifiedPercentage(int xStartingPoint, int xEndingPoint, int yStartingAndEndingPoint, int slideByPercentage) {
    double slideFactor = (double)slideByPercentage/(double)100;
    int pointToMoveTo = (int) ((xEndingPoint+offset)*slideFactor);
    touchAction = new TouchAction(driver);
    touchAction.longPress(xStartingPoint,yStartingAndEndingPoint,1000).moveTo(pointToMoveTo,yStartingAndEndingPoint).release().perform();
   }
} 
0

As you saying, it's working for one page same method not working on another page, so you can solve it yourself, Please go to Android Mobile Settings > Developer options > Input > Enable Show touches and Pointer location , then run your automation case and observe the touch action(on which page its not working), change the start point / end point / time duration as yo need, I think it will helpful for you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.