【问题标题】:Appium with Android Hydrid App doesn't recognise element带有 Android Hydrid App 的 Appium 无法识别元素
【发布时间】:2017-03-31 09:17:47
【问题描述】:

我正在为 Android 上的 Hydrid 应用编写自动化测试。我有两个问题:

  1. 在 Appium Inspector 中,我看到了一个具有属性的元素

    resource-id: login_button
    

    所以我用

    点击了这个按钮
    androidDriver.findElement(By.id("login-button")).click();
    

    我得到这个错误:

    "An element could not be located with..."
    

    当然,如果我找到带有

    的元素
    classname "android.widget.Button" 
    

    然后就可以了。我问开发者,通常resource-id 会是这样的

    resource-id: <APP_PACKAGE_NAME>:id/login_button
    

    但他说对于 Hydrid 应用程序,他没有 bundleID (APP_PACKAGE_NAME)。 Hydrid APP 没有bundleID 是否正确?以及为什么 Appium Inspector 可以看到

    "resource-id: login_button"
    

    但该元素无法找到且无法点击?

  2. 所以我也尝试使用以下代码将上下文切换到WEBVIEW

    Set<String> contextHandles = appiumDriver.getContextHandles();
    Map<String,String> hashMap= new HashMap<String,String>();
        for (String contextname : contextHandles){
            if (contextname.contains("NATIVE")){
                hashMap.put("native", contextname);
            } else {
                hashMap.put("webview", contextname);
            }
        }
        //webview 
        androidDriver.context(hashMap.get("webview"));
    

    contextHandles 有 2 个值:NATIVE_APPWEBVIEW_&lt;APP_PACKAGE_NAME&gt;。但是当我将上下文设置为webview 时,我得到了错误:

    "There is no such context"
    

有人可以帮忙吗?谢谢

【问题讨论】:

    标签: java android automated-tests appium


    【解决方案1】:

    混合应用程序是指 - 由 Native App View 和 Web View 组合构建的应用程序。

    但一次只能使用一个视图,无论是原生视图还是 Web 视图

    如果视图是原生的,那么您可以从 UI Automator 检查元素。

    如果视图是 webview,那么 UI 自动器将不会显示任何层次结构。为此,您必须使用 url 在浏览器中进行检查 - chrome://inspect/#devices

    在你的情况下,你是说如果你使用类名你可以点击登录,但当你使用资源 ID 时无法点击

    可能有多个定位器具有相同的资源 ID。请检查一次并确保您使用的唯一定位器可能是 Xpath 或类名等

    【讨论】:

      猜你喜欢
      • 2016-04-26
      • 1970-01-01
      • 2018-11-17
      • 1970-01-01
      • 2019-11-03
      • 2014-11-27
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      相关资源
      最近更新 更多