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

Unable to click delete button, multiple view

无法点击删除按钮,出现错误:

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