Java Android espresso在层次结构中找不到匹配的视图
我试图找到一个视图,并尝试了不同的组合,但根据所有的stackoverflow示例,我的逻辑看起来是正确的 我的代码:Java Android espresso在层次结构中找不到匹配的视图,java,android,kotlin,android-espresso,Java,Android,Kotlin,Android Espresso,我试图找到一个视图,并尝试了不同的组合,但根据所有的stackoverflow示例,我的逻辑看起来是正确的 我的代码: onData(anything()).inAdapterView( instanceOf(ListView::class.java)) .atPosition(0) .onChildView(withId(android.R.id.title))
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}
知道我做错了什么吗?
您可以在您的案例中尝试一下。不幸的是,我不能确定onData()如何在这里工作,但在研究之后,您应该尝试以下方法:
onView(withId(R.id.title))
.check(matches(withText("Edit")))
.check(matches(isDisplayed()));
如果您只是简单地使用:
onView(带id(R.id.title)).check(匹配项(isDisplayed())代码>有效。我很好奇我是否可以在这里做onData(),或者我不应该在这里想得太多而做得很简单