无法在Android应用的模拟器屏幕上找到该元素

时间:2018-06-06 09:46:10

标签: automation appium-android

该元素出现在appium视图中,但不幸的是,该元素在自动化时似乎不可见。

private AndroidDriver driver;
String idOfCNIC = "com.tez.androidapp:id/imageViewNICDetails";

this.driver.findElement(By.id(idOfCNIC))`

以下是驱动程序初始化代码:

private static AndroidDriver driver;

    public static AndroidDriver getDriver() {
        if (driver == null) {
            DesiredCapabilities caps = new DesiredCapabilities();
            caps.setCapability("deviceName", "920121cb3c7fc34a");
            caps.setCapability("platformName", "Android");
            caps.setCapability(CapabilityType.VERSION, "6.0.1");
            caps.setCapability(CapabilityType.BROWSER_NAME, "Android");
            caps.setCapability("app", "path_of_app");
            (InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
            try {
                driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
        return driver;
    }

1 个答案:

答案 0 :(得分:0)

您好,请使用以下版本的Appium Java客户端和Selenium:

  1. Appium Java-Client:6.0.0-BETA5
  2. Selenium-server:3.9.1 Appium
  3. 桌面为Appium Inspector:1.6.1
  4. 另请尝试使用以下代码进行驱动程序初始化:

    private static AndroidDriver<?> driver;
    
        public static AndroidDriver getDriver() {
            if (driver == null) {
                DesiredCapabilities caps = new DesiredCapabilities();
                caps.setCapability(MobileCapabilityType.DEVICE_NAME, "920121cb3c7fc34a");
                caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
                caps.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Appium ");
                caps.setCapability(MobileCapabilityType.VERSION, "6.0.1");
                caps.setCapability(MobileCapabilityType.APP, "path_of_app");
                caps.setCapability("appWaitActivity", "*");
                try {
                    driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
            }
            return driver;
        }
    

    我希望这能解决你的问题。谢谢!