微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/android/318377.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐