簡體   English   中英

使用 Appium 在 Android 本機應用程序中滾動的問題

[英]Issue with Scrolling in Android Native app using Appium

對於我的原生 Android 應用程序,過去 2 周我一直在嘗試讓 appium 在我的原生應用程序上向下滾動。 我試過driver.scrollTo("Accounts"); 然后我得到了這個錯誤

[org.openqa.selenium.WebDriverException: CATCH_ALL: io.selendroid.server.common.exceptions.SelendroidException: method (by) not found: -android uiautomator

以及我發現的許多其他示例。 似乎沒有任何效果。 這是我嘗試過的最新示例。

使用 appium 1.5.2 和 appium java 客戶端版本:'3.3.0'。 當我嘗試運行以下代碼時。

    TouchAction tAction=new TouchAction(driver);
    int startx = driver.findElement(By.id("line_chart_line_chart")).getLocation().getX();
    int starty = driver.findElement(By.id("line_chart_line_chart")).getLocation().getY();
    int endx = driver.findElement(By.id("actionBarLogo")).getLocation().getX();
    int endy = driver.findElement(By.id("actionBarLogo")).getLocation().getY();
    System.out.println(startx + " ::::::: " + starty + " ::::::: " + endx +  " ::::::: " +  endy);
    //  This is what the console printed out  startX=560 ::::::: starty=1420 ::::::: endx=560 ::::::: endy=240  
    //First tap on the screen and swipe up using moveTo function
    tAction.press(startx,starty).moveTo(endx,endy).release().perform();

然后我收到此錯誤消息

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy 
error: Could not proxy command to remote server. Original error: 404 - undefined (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 27 milliseconds

我不知所措。 為了點擊一個元素,它必須在屏幕上可見。 為了讓這個元素出現在屏幕上,我需要向下滾動到它。

有什么我做錯了嗎??? 我似乎無法弄清楚。

您使用了 Selendroid 模式,該模式不支持 UiAutomator By 方法。 您可以通過將所需的功能automationName Appium設置為 Appium,將您的 appium 運行模式更改為Appium

這個函數對我有用,在你的情況下調用它時為 elementName 放入“帳戶”。

public static void scrollToElementAndroid(AndroidDriver driver, String elementName, boolean scrollDown) {
    String listID = ((RemoteWebElement) driver.findElementByAndroidUIAutomator("new UiSelector().className(android.widget.ListView)")).getId();
    String direction;
    if (scrollDown) {
        direction = "down";
    } else {
        direction = "up";
    }
    HashMap<String, String> scrollObject = new HashMap<String, String>();
    scrollObject.put("direction", direction);
    scrollObject.put("element", listID);
    scrollObject.put("text", elementName);
    driver.executeScript("mobile: scrollTo", scrollObject);
}

使用如下代碼:

Dimension size = driver.manage().window().getSize();
int x = size.width / 2;
int endy = (int) (size.height * 0.75);
int starty = (int) (size.height * 0.20);
driver.swipe(x, starty, x, endy, 1000);

暫無
暫無

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

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