Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

java - Android - Appium Swipe down not working

I am trying to swipe down contact screen but its not working.

Here is the code I have tried.

public void Swipedown() throws InterruptedException
{
  // Select till which position you want to move the seekbar
  TouchAction action=new TouchAction((PerformsTouchActions) driver);
  Dimension dimensions = driver.manage().window().getSize();

  action.press(446,1404).moveTo(554,1500).release().perform(); 

    System.out.println("swipe down to set seekbar successfully");
    Thread.sleep(5000);
    }

Can you guys help me what I am doing wrong here.
Any help will be highly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use below method for swiping down/up:

public static void swipeVertical(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
        Dimension size = driver.manage().window().getSize();
        int anchor = (int) (size.width * anchorPercentage);
        int startPoint = (int) (size.height * startPercentage);
        int endPoint = (int) (size.height * finalPercentage);
        new TouchAction(driver).press(anchor, startPoint).waitAction(Duration.ofMillis(duration)).moveTo(anchor, endPoint).release().perform();
    }

Call above method by:

For scroll up: swipeVertical((AppiumDriver)driver,0.9,0.1,0.5,3000);

For scroll down: swipeVertical((AppiumDriver)driver,0.1,0.9,0.5,3000);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...