簡體   English   中英

頁面滾動沒有發生appium java客戶端

[英]page scroll is not happening appium java client

我正在為我的應用程序進行自動化移動測試。在輸入用戶名和密碼后的登錄頁面中, 鍵盤會 彈出並阻止屏幕上的所有內容 因此它會拋出一個元素無法使用給定的搜索參數位於頁面上org.openqa.selenium.NoSuchElementException:要啟用滾動或屏幕觸摸,我嘗試了很多方法。

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

我無法解決此問題..請您使用一些示例代碼向我建議以解決此問題。

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

輸入用戶名和密碼后,您可以使用以下代碼行:

driver.hidekeyboard();

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM