Android Espresso ListView单击项 [英] Android Espresso ListView click item

查看:189
本文介绍了Android Espresso ListView单击项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ListView带有图片和文字.当我尝试单击项目时,出现错误

I have ListView with pictures and text. When I try to click item, I get error

android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.cifrasoft.telefm:id/cardsGridView' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.

我使用以下代码:

onData(hasToString(startsWith("Item Text")))
            .inAdapterView(withId(R.id.cardsGridView))
            .perform(click());

我可以使用Adapter的位置单击ListView,而没有匹配项或startWith吗?

Can I click ListView using position of Adapter, without matches or startWith?

推荐答案

尝试使用atPosition().例如

Try with atPosition(). e.g.

onData(hasToString(startsWith("Item Text")))
            .inAdapterView(withId(R.id.cardsGridView)).atPosition(0)
            .perform(click());

索引为0,它将单击找到的第一个匹配视图.

with index 0, it will click on the first matching view found.

这篇关于Android Espresso ListView单击项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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