【发布时间】: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