I have tried making this scroll up method but its not working fine, hereās the code
public static boolean scrollToElement (By by) throws Exception {
boolean isFoundTheElement = driver.findElements(by).size() > 0;
while (isFoundTheElement == false) {
scrollDown(0.8, 0.1, 0.5, 2000);
scrollUp(0.1,0.8,0.5, 2000);
//scroll(0.1,0.9,0.5,3000); //scrolldown
//scroll(0.9,0.1,0.5,3000); //scrollup
isFoundTheElement = driver.findElements(by).size() > 0;
}
return isFoundTheElement;
}
public static void scrollDown (
double startPercentage, double finalPercentage, double anchorPercentage, int duration)
throws Exception {
org.openqa.selenium.Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.width * anchorPercentage);
int startPoint = (int) (size.height * startPercentage);
int endPoint = (int) (size.height * finalPercentage);
getTouchAction().press(PointOption.point(anchor, startPoint))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration)))
.moveTo(PointOption.point(anchor, endPoint)).release().perform();
}
public static void scrollUp (
double startPercentage, double finalPercentage, double anchorPercentage, int duration)
throws Exception {
org.openqa.selenium.Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.width * anchorPercentage);
int startPoint = (int) (size.height * finalPercentage);
int endPoint = (int) (size.height * startPercentage);
getTouchAction().press(PointOption.point(endPoint, anchor))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(duration)))
.moveTo(PointOption.point(anchor,startPoint)).release().perform();
}