automation - 无法单击删除按钮,多视图
问题描述
无法单击删除按钮,出现错误:
android.support.test.espresso.AmbiguousViewMatcherException: '(with id: cit:id/delete_button and has parent matching: with id: cit:id/count_and_delete and is displayed on the screen to the user)' matches multiple views in the hierarchy.
我正在使用以下代码单击删除图标:
ViewInteraction appCompatImageView222 = onView(
allOf(withId(R.id.delete_button),
withParent(withId(R.id.count_and_delete)),
isDisplayed()));
appCompatImageView222.perform(actionOnItemAtPosition(0, click()));
ViewInteraction appCompatImageView222 = onView(
allOf(withId(R.id.delete_button),
withParent(withId(R.id.count_and_delete)),
isDisplayed()));
appCompatImageView222.perform(click());
解决方案
您的匹配器allOf(withId(R.id.delete_button), withParent(withId(R.id.count_and_delete)), isDisplayed()))
仍然不够独特,因为它仍然在您的屏幕上找到两个视图匹配器。相反,尝试匹配其祖父视图中的文本:
onView(allOf(
withId(R.id.delete_button),
withParent(withParent(withChild(withText("Count 1"))))))
.check(matches(isDisplayed()))
.perform(click())
推荐阅读
- python - 获取“只能使用带有字符串值的 .str 访问器!” 熊猫数据框中没有要处理的记录时出错
- html-table - Google App Script - 在表单中将记录从工作表拉到 HTML 表的示例
- javascript - useMemo 可以在匿名函数中使用吗?
- angular - Ionic + PWA - 在浏览器中显示启动画面
- reactjs - 从对象反应 img src
- sql - 使用表单字段作为标准的 DELETE 查询要求提供参数而不是从表单中提取
- python-xarray - 尽管时间不是我的 3D 矩阵的维度,但构建一个时间可选的 python xarray
- reactjs - 从嵌套组件更改 MUI 主题
- python-3.x - PyMongo:如何从光标中读取前 n 个项目?
- python - 熊猫石斑鱼“累积” sum()