gpt4 book ai didi

android - 在 Recycler View 内单击 : Espresso

转载 作者:行者123 更新时间:2023-12-02 20:58:28 24 4
gpt4 key购买 nike

我正在尝试单击 Recycler View 中的菜单项,并且我有以下代码。

onView(allOf(withId(R.id.section_list),isDisplayed())).perform(RecyclerViewActions.actionOnItem(hasDescendant(withText("ABC")), MyViewAction.clickChildViewWithId(R.id.payment_menu)));

MyViewAction 看起来像这样:

class MyViewAction {

public static ViewAction clickChildViewWithId(final int id) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return null;
}

@Override
public String getDescription() {
return "Click on a child view with specified id.";
}

@Override
public void perform(UiController uiController, View view) {
View v = view.findViewById(id);
v.performClick();
}
};
}
  • 当我测试它时,我可以看到滚动发生到正确的位置,但点击失败并出现以下错误

android.support.test.espresso.PerformException: Error performing 'android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction@2fd64b56' on view 'with id: com.em3Agri.operation.debug:id/section_list'. at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83) at ......... Caused by: java.lang.IllegalStateException: No view holder at position: 38 at android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction.perform(RecyclerViewActions.java:290) at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)

最佳答案

怎么样:

onView(withId(R.id.section_list))
.perform(
RecyclerViewActions.actionOnItem(
hasDescendant(withId(R.id.payment_menu)),
ViewActions.click()
)
);

关于android - 在 Recycler View 内单击 : Espresso,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39710805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com