无法单击删除按钮,多视图

时间:2018-10-23 11:04:33

标签: automation ui-automation android-espresso android-espresso-recorder

Unabel单击删除按钮,出现错误:

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

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

您的匹配器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())