Android espresso找不到层次结构中的视图匹配

问题描述 投票:0回答:1

我试图找到一个视图并尝试了不同的组合,但是根据所有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

java android kotlin android-espresso
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.