【问题标题】:Appium scroll action happening twiceAppium 滚动动作发生两次
【发布时间】:2020-05-25 09:52:08
【问题描述】:

我正在使用下面的代码在 iOS 设备上滚动屏幕,但它滚动了两次。我在屏幕中有多个同名元素,但我想滚动到第一个元素。

 JavascriptExecutor js = (JavascriptExecutor) driver;
         HashMap<String, String> scrollObject = new HashMap<String, String>();
         scrollObject.put("direction", "down");
         scrollObject.put("xpath", "//XCUIElementTypeStaticText[@name='Max threshold (L/s)']");
         js.executeScript("mobile: scroll", scrollObject);

【问题讨论】:

    标签: java ios selenium automation appium


    【解决方案1】:

    将序列号添加到您的xpath

    scrollObject.put("xpath", "(//XCUIElementTypeStaticText[@name='Max threshold (L/s)'])[1]");
    

    【讨论】:

    • 它仍然滚动两次,它并没有在目标元素处停止。有什么方法可以滚动到 iOS 应用程序的目标元素。
    • 我使用了下面的代码,它对我来说工作正常。 public void verticalSwipeOnce(double scrollPercentageStart, double scrollPecentageEnd) { Dimension dim = driver.manage().window().getSize(); int height = dim.getHeight(); int starty = (int) (height * scrollPercentageStart); int endy = (int) (height * scrollPecentageEnd); new TouchAction((PerformsTouchActions) (driver)).press(PointOption.point(0, starty)) .waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(0, endy))。释放()。执行(); }
    • @cindy87 只是建议,如果这解决了您的问题,请将其作为答案发布。
    【解决方案2】:

    下面的代码帮助了我,

    public void verticalSwipeOnce(double scrollPercentageStart, double scrollPecentageEnd) {
    
    Dimension dim = driver.manage().window().getSize();
    int height = dim.getHeight(); int starty = (int) (height * scrollPercentageStart);
    int endy = (int) (height * scrollPecentageEnd);
    new TouchAction((PerformsTouchActions) (driver)).press(PointOption.point(0, starty)) .waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(0, endy)) .release().perform();
    
     }
    

    【讨论】:

      猜你喜欢
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      • 1970-01-01
      • 2021-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多