Wednesday, February 4, 2026

Tips on how to scroll horizontally realizing that the required tab has no distinctive ID (Appium utilizing Java)


Along with Dmitri’s strategies, you may as well use TouchActions, as I do in my code:

/**
 * This methodology scrolls primarily based upon the handed parameters
 * @creator Invoice Hileman
 * @param int startx - the beginning x place
 * @param int starty - the beginning y place
 * @param int endx - the ending x place
 * @param int endy - the ending y place
 */
@SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {

    TouchAction touchAction = new TouchAction(driver);

    touchAction.longPress(PointOption.level(startx, starty))
               .moveTo(PointOption.level(endx, endy))
               .launch()
               .carry out();

}

/**
 * This methodology does a swipe upwards
 * @creator Invoice Hileman
 */
public void scrollDown() {

    //The viewing measurement of the gadget
    Dimension measurement = driver.handle().window().getSize();

    //Beginning y location set to 80% of the peak (close to backside)
    int starty = (int) (measurement.peak * 0.80);
    //Ending y location set to twenty% of the peak (close to prime)
    int endy = (int) (measurement.peak * 0.20);
    //x place set to mid-screen horizontally
    int startx = (int) measurement.width / 2;

    scroll(startx, starty, startx, endy);

}

/**
 * This methodology does a swipe left
 * @creator Invoice Hileman
 */
public void swipeLeft() {

    //The viewing measurement of the gadget
    Dimension measurement = driver.handle().window().getSize();

    //Beginning x location set to 95% of the width (close to proper)
    int startx = (int) (measurement.width * 0.95);
    //Ending x location set to five% of the width (close to left)
    int endx = (int) (measurement.width * 0.05);
    //y place set to mid-screen vertically
    int starty = measurement.peak / 2;

    scroll(startx, starty, endx, starty);

}

/**
 * This methodology does a swipe proper
 * @creator Invoice Hileman
 */
public void swipeRight() {

    //The viewing measurement of the gadget
    Dimension measurement = driver.handle().window().getSize();

    //Beginning x location set to five% of the width (close to left)
    int startx = (int) (measurement.width * 0.05);
    //Ending x location set to 95% of the width (close to proper)
    int endx = (int) (measurement.width * 0.95);
    //y place set to mid-screen vertically
    int starty = measurement.peak / 2;

    scroll(startx, starty, endx, starty);

}

/**
 * This methodology does a swipe downwards
 * @creator Invoice Hileman
 */
public void scrollUp() {

    //The viewing measurement of the gadget
    Dimension measurement = driver.handle().window().getSize();

    //Beginning y location set to twenty% of the peak (close to backside)
    int starty = (int) (measurement.peak * 0.20);
    //Ending y location set to 80% of the peak (close to prime)
    int endy = (int) (measurement.peak * 0.80);
    //x place set to mid-screen horizontally
    int startx = measurement.width / 2;

    scroll(startx, starty, startx, endy);

}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles