【问题标题】:Scroll issue in android native appandroid本机应用程序中的滚动问题
【发布时间】:2017-05-20 00:19:54
【问题描述】:

我正在使用 appium 和 java 来自动化我的应用程序。我需要滚动页面直到特定的文本/元素。两天以来我一直在苦苦挣扎,并尝试了许多解决方案,但它不起作用。列出所有解决方案和方案:

Appium 版本:1.4.0 Java客户端版本:4.1.2 驱动:RemoteWebDriver

解决方案1.1: 尝试使用 Java 脚本。代码如下:

JavascriptExecutor js = (JavascriptExecutor)driver;
HashMap scrollObjects = new HashMap();
scrollObjects.put("direction", "down");
scrollObjects.put("text", "Yes");
js.executeScript("mobile: swipe", scrollObjects)

解决方案 1.2:

WebElement wb = driver.findElement(By.xpath("//*[@resource-id =           'com.practo.fabric:id/toolbar']/following-sibling::android.widget.LinearLayout"));
JavascriptExecutor js = (JavascriptExecutor)driver;
HashMap scrollObjects = new HashMap();
scrollObjects.put("direction", "down");
scrollObjects.put("text", "Yes");
scrollObjects.put("element",wb);
js.executeScript("mobile: swipe", scrollObjects);

这里的问题是我没有列表视图。我有线性布局,所以也尝试过提供线性布局 xpath 一次,但没有成功。

解决方案2:

org.openqa.selenium.Dimension size =driver.manage().window().getSize();     
int starty = (int) (size.height * 0.80); 
int endy = (int) (size.height * 0.20);
int startx = size.width / 2; 
driver.swipe(startx, starty, startx, endy, 3000); 
System.out.println("swiping is done ");

这里 driver.swipe 给出错误,因为我是 RemoteWebDriver。当我尝试使用 AndroidDriver 时,它说已弃用。

在这种情况下我该怎么办?

【问题讨论】:

    标签: javascript android scroll appium


    【解决方案1】:

    由于 appium 服务器和 java 客户端库版本不匹配,您正面临问题。请将 appium 服务器更新为 1.5/1.6,否则您可以使用 java-client 库版本 2.1.0。

    如果您选择在 appium 1.4 中使用 java-client2.1.0,我们将有一个名为“scrollTo”的方法,它可以滚动到特定的文本。正如您在此组合中的解决方案 2 中提到的那样,我还使用了“滑动”。

    driver.scrollTo("Like"); //Scrolls to Like text in the app
    

    【讨论】:

      【解决方案2】:

      我通过使用 java-client 中的 AppiumDriver 解决了这个问题。当我使用最新的 java-client 版本(5.0.0-BETA6)时,它说“刷卡”方法已被弃用。但它有效。

      driver.swipe(300, 701, 300, 441, 3000);
      

      也使用 TouchAction 类解决了这个问题。

      TouchAction action = new TouchAction(driver);   
      action.press(300, 701).waitAction(2000).moveTo(300, 441).release();
      action.perform();
      

      注意:坐标是硬编码的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-05
        • 1970-01-01
        • 2010-10-24
        • 1970-01-01
        • 2016-04-05
        相关资源
        最近更新 更多