android – 使用onView时使用Espresso点击操作栏中的菜单项(withId(…))

我正在使用Espresso进行测试,首先打开操作栏:
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

一切都还可以,但我想点击一个选项菜单

onView(withId(R.id.action_menu)).perform(click());

菜单布局xml有一个id为“action_menu”的选项.

我收到一个错误

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: ***.********.******.android.debug:id/action_menu
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:android.support.v7.widget.ListPopupWindow$dropdownlistview{43fd3f58 VFED.VC. .F...... 24,24-612,168}

我通过使用以下方法来完成这一步:

onView(withText(R.string.action_report)).perform(click());

我想知道id有什么问题.

有任何想法吗?

解决方法

似乎表示菜单的视图不知道id,而只知道项目的文本.
我是Espresso的新手,因此无法提供更多详细信息,但这篇文章与您的问题有关:
Espresso NoMatchingViewException when using withId matcher

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...