Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android espresso在层次结构中找不到匹配的视图_Java_Android_Kotlin_Android Espresso - Fatal编程技术网

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

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))

我试图找到一个视图,并尝试了不同的组合,但根据所有的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}
知道我做错了什么吗?

您可以在您的案例中尝试一下。不幸的是,我不能确定onData()如何在这里工作,但在研究之后,您应该尝试以下方法:

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

如果您只是简单地使用:
onView(带id(R.id.title)).check(匹配项(isDisplayed())有效。我很好奇我是否可以在这里做onData(),或者我不应该在这里想得太多而做得很简单