[英]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.