java - Android espresso 在层次结构中找不到匹配的 View

标签 java android kotlin android-espresso

我试图找到一个 View 并尝试了不同的组合,但根据所有 stackoverflow 示例,我的逻辑看起来都是正确的。

我的代码:

onData(anything()).inAdapterView(
                   instanceOf(ListView::class.java))
                .atPosition(0)
                .onChildView(withId(android.R.id.title))
                .check(matches(withText("Edit")))
                .check(matches(isDisplayed()))

它会抛出错误:

E/TestRunner: androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: android:id/title and is descendant of a:  displaying data matching: ANYTHING within adapter view matching: an instance of android.widget.ListView)
    If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:androidx.appcompat.widget.MenuPopupWindow$MenuDropDownListView{3df3337 VFED.VC.. ........ 0,0-539,264}

你知道我做错了什么吗? enter image description here

最佳答案

您可以根据您的情况尝试一下。不幸的是,我无法确定 onData() 在这里如何工作,但在研究之后你应该尝试这样的事情:

onView(withId(R.id.title))
    .check(matches(withText("Edit")))
    .check(matches(isDisplayed()));

关于java - Android espresso 在层次结构中找不到匹配的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60200742/

相关文章:

java - 具有 MEAN 堆栈和 Java 的 Webapp

java - 无法单击未聚焦的 EditText 字段

android - 移动设备之间的实时P2P通信

Android Horizo​​ntalScrollView 禁用滚动

java - 从 ViewModel 调用变量的最佳实践

csv - Kotlin 反射 - 从 CSV 创建对象

kotlin - 如何在一行中输入五个以上的值?

java - 如何解决 hibernate 中的目标未映射类错误?

java - Maven依赖问题: Provided and Compile dependencies working together

java - 使用 NewGlobalRef 时的 JNI "local reference table overflow"