Scroll to a specific item

Hello, I’ve been working in the field of testing for a year now, I also do test automation. I can’t scroll to the element, read the documentation, also read what other users write, but still can’t scroll. Who can help me with this on a living example or throw off a working manual?

use this method

public void scrollVerticalOnElement(double startPercent,double endPercent,WebElement el)
{
Dimension dimensions = el.getSize();
Point p=el.getLocation();

int minY=p.getY();
int x=(int) (p.getX()+(dimensions.getWidth()/2));

int scrollStart = (int) (minY+dimensions.getHeight() * startPercent);
int scrollEnd = (int) (minY+dimensions.getHeight() * endPercent);         
swipe(x,scrollStart,x,scrollEnd,500); 

}

1 Like

@Battrip -> Swipe/Scroll best practice with Java-Client 5

1 Like

Hello. What is the swipe method? I use the appium library and selenium I do not have a similar method

/**

  • Performs swipe from point (startx,starty) to (endx,endy) in duration provided in milliseconds
  • @param startx : x coordinate of point from where we should start swipe
  • @param starty : y coordinate of point from where we should start swipe
  • @param endx : x coordinate of destination point where we should reach after swipe
  • @param endy : y coordinate of destination point where we should reach after swipe
  • @param duration : duration in milliseconds required to perform action (approx)
    */

public void swipe(int startx, int starty, int endx, int endy, long duration) {
TouchAction touchAction = new TouchAction(ad);
// appium converts press-wait-moveto-release to a swipe action
touchAction.press(PointOption.point(startx, starty))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration)))
.moveTo(PointOption.point(endx, endy))
.release().perform();
}

1 Like