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:使用给定的搜索参数无法在页面上找到元素。
使用swipe时出错:java.lang.NullPointerException
答案 0 :(得分:0)
我使用此代码在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);
希望它能帮到你。
答案 1 :(得分:0)
创建了一个滑动(包裹)的功能
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();
答案 2 :(得分:0)
您可以使用屏幕坐标向下滚动:
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);
}