[英]Unable to scroll down in android with appium
Appium版本:1.4.0.0
作业系统:Windows 7
程式库:android.AndroidDriver
selenium.WebDriver
我正在使用Java实现Appium的自动化
我试过下面的代码。
driver.swipe(381, 783, 364, 218, 3000);
driver.scrollTo("Confirm");
driver.scrollToExact("Confirm");
使用scrollto时发生错误:org.openqa.selenium.NoSuchElementException:使用给定的搜索参数无法在页面上找到元素。
使用滑动时发生错误:java.lang.NullPointerException
我使用以下代码在IOS中垂直滑动:
Dimension size = driver.manage().window().getSize();
int starty = (int) (size.height * 0.80);
//Find endy point which is at top side of screen.
int endy = (int) (size.height * 0.20);
//Find horizontal point where you wants to swipe. It is in middle of screen width.
int startx = size.width / 2;
//Swipe from Bottom to Top.
driver.swipe(startx, starty, startx, endy, 3000);
makeWait(2);
希望对你有帮助。
创建了滑动功能(包裹)
public void scroll() throws IOException {
try {
Dimension dimensions = driver.manage().window().getSize();
System.out.println("Size of Window= " +dimensions);
int scrollStart = (int) (dimensions.getHeight() * 0.5);
System.out.println("Size of scrollStart= " +scrollStart);
int scrollEnd = (int) (dimensions.getHeight() * 0.2);
System.out.println("Size of cscrollEnd= " + scrollEnd);
driver.swipe(0,scrollStart,0,scrollEnd,1000);
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
将此添加到我们的代码中,只需使用scroll();
在您的测试案例中
您可以使用屏幕坐标向下滚动:
public void scrollDown() {
Dimension size = driver.manage().window().getSize();
int x = size.width / 2;
int starty = (int) (size.height * 0.60);
int endy = (int) (size.height * 0.10);
driver.swipe(x, starty, x, endy, 2000);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.