2017-09-15 26 views
3

我做自動化移動測試我的應用程序。在登錄頁面的屏幕輸入用戶名密碼&,鍵盤彈出,塊都記錄下來了。因此它被拋出使用給定的搜索參數無法在頁面上找到一個元素org.openqa.selenium.NoSuchElementException: 要啓用滾動或屏幕觸摸,我嘗試了很多方法。頁面滾動沒有發生appium Java客戶端

1) 
 
WebElement element1 = driver.findElement(MobileBy.AccessibilityId("btnLogin")); 
 
\t \t int x = element1.getLocation().getX(); 
 
\t \t int y = element1.getLocation().getY(); 
 
\t \t TouchAction action = new TouchAction((PerformsTouchActions) driver); 
 
\t action.press(x,y).moveTo(x,y-90).release().perform(); 
 
    
 
    2) 
 
    WebElement element1 = driver.findElement(MobileBy.AccessibilityId("btnLogin")); 
 
\t ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);",element1); 
 
    
 
    3) 
 
    
 
    TouchAction action = new TouchAction((PerformsTouchActions) driver); 
 
\t WebElement element1 = driver.findElement(MobileBy.AccessibilityId("com.a.b:id/imageView")); 
 
\t WebElement element2 = driver.findElement(MobileBy.AccessibilityId("com.a.b:id/btnLogin")); 
 
\t action.press(element1).moveTo(element2).release(); 
 
    
 
    4) 
 
    JavascriptExecutor js = (JavascriptExecutor) driver; 
 
\t HashMap<String, String> scrollObject = new HashMap<String, String>(); 
 
\t scrollObject.put("direction", "up"); 
 
\t scrollObject.put("element", "btnLogin"); 
 
\t js.executeScript("mobile: scroll", scrollObject); 
 
    
 
    5) 
 
    ((AndroidDriver) driver).context("NATIVE_APP"); 
 
\t WebElement element = driver.findElementById("btnLogin"); 
 
\t int x = element.getSize().getWidth(); 
 
    int xEnd = 0; 
 
\t int yStart = element.getSize().getHeight()/2; 
 
\t ((AndroidDriver) driver).swipe(x, yStart, xEnd, yStart, 500);

我不能夠解決這個問題..你可以請建議我一些示例代碼來解決這個問題。

回答

1

要隱藏鍵盤,您可以使用以下方法driver.hideKeyboard()。這與AppiumDriver一起工作。

輸入您的用戶名和密碼後,您可以使用此行代碼:

driver.hidekeyboard();

+0

我得到的那一天。對於滾動我需要更多的信息。 – Santosh

0
public static void swipeVertical(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception { 
    Dimension size = driver.manage().window().getSize(); 
    int anchor = (int) (size.width * anchorPercentage); 
    int startPoint = (int) (size.height * startPercentage); 
    int endPoint = (int) (size.height * finalPercentage); 
    new TouchAction(driver).press(anchor, startPoint).waitAction(duration).moveTo(anchor, endPoint).release().perform(); 
} 

調用上面的方法,如:

對於向上滾動:swipeVertical((AppiumDriver)driver,0.9,0.1,0.5,3000);

對於向下滾動:swipeVertical((AppiumDriver)driver,0.1,0.9,0.5,3000);