使用Appium和Desired功能,我正在设备中启动android应用程序,但无法导航到不在同一页面的屏幕视图中的元素,JavascriptExecutor也与appium代码不兼容。我使用了UIAutomator查看器来识别对象。我们只需要向下滚动到最后才能识别这些对象,但是JavascriptExecutor也与appium代码不兼容,并使用Keys.END和Keys。ARROW_DOWN我也是无法识别不在同一页面的屏幕视图中的对象。

最佳答案

请先向下滑动组合,以使元素可见,然后再与之交互。代码示例-
    HashMap swipeObject =新的HashMap();

    WebElement we = driver.findElement(By.xpath("/relative"));
    Dimension screenSize = driver.manage().window().getSize();
    Double screenWidth = Double.valueOf(String.valueOf(screenSize.getWidth())) / 2;
    Double screenHeight = Double.valueOf(String.valueOf(screenSize.getHeight())) / 2;
    swipeObject.put("startX", (screenWidth));
    swipeObject.put("startY", screenHeight + 100);
    swipeObject.put("endX", (screenWidth));
    swipeObject.put("endY", (screenHeight));
    swipeObject.put("duration", 1.0);
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
    while (!elementPresent(driver,by, 2)) {
        js.executeScript("mobile: swipe", swipeObject);
        Thread.sleep(1000);
    }
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}

07-27 22:00