Find out how to scroll horizontally understanding that the required tab has no distinctive ID (Appium utilizing Java)

0
28
Find out how to scroll horizontally understanding that the required tab has no distinctive ID (Appium utilizing Java)


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

/**
 * This technique scrolls based mostly 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 technique does a swipe upwards
 * @creator Invoice Hileman
 */
public void scrollDown() {

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

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

    scroll(startx, starty, startx, endy);

}

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

    //The viewing measurement of the system
    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.top / 2;

    scroll(startx, starty, endx, starty);

}

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

    //The viewing measurement of the system
    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.top / 2;

    scroll(startx, starty, endx, starty);

}

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

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

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

    scroll(startx, starty, startx, endy);

}

LEAVE A REPLY

Please enter your comment!
Please enter your name here