使用带有动态元素ID的espresso android进行DropDown值选择 [英] DropDown value selection using espresso android with dynamic element id's

查看:53
本文介绍了使用带有动态元素ID的espresso android进行DropDown值选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PopupWindow$PopupViewContainer(@xxxxxxxx)
--ListPopupWindow$DropDownListView(@yyyyyyyy)
  --RelativeLayout(@zzzzzzz)
    ImageView
    TextView
  --RelativeLayout(@aaaaaaaa)
    ImageView
    TextView
  --RelativeLayout(@aaaaaaaa)
    ImageView
    TextView

我想知道如何使用espresso android自动化访问RelativeLayout 2中的TextView,因为@id不存在并且值是动态分配的.

I want to know how to access the the TextView in RelativeLayout 2 using espresso android automation, as @id is not present and values are assigned dynamically.

上面是下拉列表,我想单击第二个选择.

The above is the dropdown list and I want to click second choice.

例如,当我们在任何搜索框中搜索项目时,我们都会填充列表.我想单击列表中的第二个.所有元素ID都是动态的.

e.g like when we search item in any search box we get list populated. And I want to click the second one in the list populated. All the element id's are dynamic.

推荐答案

我在这个问题上苦苦挣扎,发现您需要结合使用withText选择视图和一个名为RootMatchers.isPlatformPopup()的选项,尝试在诸如自动完成视图之类的视图中找到匹配的文本,并且它实际上是为此目的而设计的.

I was struggling with this issue and I found that you need to use a combination of withText to select the view and an option called RootMatchers.isPlatformPopup() which will try and find the matching text within views such as the autocomplete view and it is actually designed for this purpose.

它应该看起来像;

onView(withText("matching text"))
.inRoot(RootMatchers.isPlatformPopup())
.perform(click());

这篇关于使用带有动态元素ID的espresso android进行DropDown值选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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