【问题标题】:Android - Appium Swipe down not workingAndroid - Appium 向下滑动不起作用
【发布时间】:2018-11-11 04:31:00
【问题描述】:

我正在尝试向下滑动联系人屏幕,但它不起作用。

这是我尝试过的代码。

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);
    }

你们能帮我看看我在这里做错了什么吗?
任何帮助将不胜感激。

【问题讨论】:

    标签: java android automation appium appium-android


    【解决方案1】:

    使用以下方法向下/向上滑动:

    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();
        }
    

    通过以下方式调用上述方法:

    向上滚动:swipeVertical((AppiumDriver)driver,0.9,0.1,0.5,3000);

    向下滚动:swipeVertical((AppiumDriver)driver,0.1,0.9,0.5,3000);

    【讨论】:

    • 无法使用 [class io.appium.java_client.AppiumDriver, double, double, double, int] 注入 @Test 注释方法 [swipeVertical]。
    【解决方案2】:

    使用此代码上下滑动

    TouchAction t=new TouchAction(driver);
    
    //long press, for atleast 1 sec first and move the object
    
            WebElement First=driver.findElementByXPath("//*[@***First Element Path***]");
    
            WebElement second=driver.findElementByXPath("//*[@***Second Element Path***]");
    t.longPress(longPressOptions().withElement(element(First)).withDuration(ofSeconds(3))).moveTo(element(second)).release().perform();
    

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 2020-11-04
      • 2016-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多