Clicking on one of many views with same id in Espresso

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-05 13:37:42

问题


I have a layout (A) that includes another layout (B) multiple times. Layout B contains a button with id R.id.my_button. As a result, layout A contains many of those buttons with the same id.

How do I test clicking on any of those buttons with espresso?

onView(withId(R.id.my_button)).perform(click()); doesn't really do anything in this case.


回答1:


Probably, your layout B contains also some unique information, let's say TextView with unique name. In this case your code will look like this:

onView(allOf(withId(R.id.my_button), hasSibling(withText("unique name")))).perform(click());

More examples can be found in Espresso Wiki # ViewMatchers.



来源:https://stackoverflow.com/questions/32354340/clicking-on-one-of-many-views-with-same-id-in-espresso

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!