单击Espresso中具有相同ID的许多视图之一 [英] Clicking on one of many views with same id in Espresso

查看:87
本文介绍了单击Espresso中具有相同ID的许多视图之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局(A),其中多次包含另一个布局(B).布局B包含一个ID为R.id.my_button的按钮.结果,布局A包含许多具有相同ID的按钮.

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());在这种情况下实际上什么也没做.

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

推荐答案

可能,布局B也包含一些独特的信息,例如TextViewunique name.在这种情况下,您的代码将如下所示:

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

更多示例可在 Espresso Wiki#ViewMatchers .

这篇关于单击Espresso中具有相同ID的许多视图之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆