【问题标题】:Android UI testing: how to click to Android dialog?Android UI 测试:如何点击到 Android 对话框?
【发布时间】:2019-11-27 08:09:36
【问题描述】:

问题:
我无法运行测试,因为当 Activity 使用全屏模式时,会显示 Android 对话框(见图)。

目标:
我想点击GOT IT并关闭对话框。

代码(Kotlin):

//device is instance of UiDevice UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())

val gotIt = device.findObject(UiSelector()
        //.clickable(true)
        //.checkable(false)
        //.className("android.widget.Button")
        //.packageName("com.android.launcher3")
        //.resourceId("android:id/ok")
        //.index(3) //by index for language-independent
          .text("GOT IT")
)
if (gotIt.waitForExists(3000)) {
    try {
        return gotIt.click()
    } catch (e: UiObjectNotFoundException) {
        e.printStackTrace()
    }
} else Log.i(TAG, "clickViewingFullscreenDialog: btn not exists")

我尝试了多种选择器组合,但我仍然无法点击GOT IT。选择器是正确的,但对话框是“不可见的”或无法聚焦的。无法点击对话框。

其他信息:
试用模拟器 Nexus 5 Android 7.0。
我尝试uiautomatorviewerlayoutinspector 来获取有关View hierarchy 的信息以找到这个Android Dialog,但我只能获取有关android home screen 的信息(见第二张图片),而不是关于自己的Activity(第一张图片) .

【问题讨论】:

    标签: android ui-automation android-uiautomator


    【解决方案1】:

    “知道了”是积极的还是中性的按钮? 如果是肯定的,请点击 ID android.R.id.button2. 如果是中性按钮,请点击 ID android.R.id.button3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多