我想滚动到显示的当前屏幕的底部,但是

  • 应用程序没有任何ScrollView。应用程序具有Horizo​​ntalScrollView,但没有上下文。
  • 在屏幕上使用onView,TableLayout和ID。但是它会在匹配层次结构中的多个视图时引发错误。
  • 使用onView,通过获取firstChild(),但仍会引发错误,无法执行操作,在“具有parentMatcher类型的第一个子视图”的视图上执行“滚动到”时出错。
  • 尝试使用onData(hasToString(startsWith()。但是它会引发错误,与层次结构中的多个视图匹配。)
  • 尝试了其他方式,例如获取当前的Monitor和Activity,但仍然无法正常工作。
  • 最佳答案

    好的,根据您问题中的不足信息,我可以建议您:

  • 简单方法(但不完全正确)-只需向上滑动GridView进入其底部即可:
    onView(withId(R.id.GridView_Id)).perform(swipeUp());
    
  • 简单方法:
    onData(instanceOf(Object_in_the_ROW.class))
        .inAdapterView(withId(R.id.GridView_Id))
        .atPosition(2)  //position # can very if you have header or not
        .check(matches(isDisplayed()))
        .perform(click());  //or any other action, or no action
    
  • 我更喜欢的方法:
    onData(withROWText("unique_text_in_ROW3"))
        .inAdapterView(withId(R.id.GridView_Id))
        .check(matches(isDisplayed()))
        .perform(click());
    

  • 其中withRowText()是用于匹配ROW3中特定文本的自定义匹配器,例如:
    public static Matcher<Object> withRowText(String expectedText) {
        Checks.checkNotNull(expectedText);
        return withRowText(equalTo(expectedText));
    }
    
    public static Matcher<Object> withRowText(final Matcher<String> itemTextMatcher) {
        Checks.checkNotNull(itemTextMatcher);
        return new BoundedMatcher<Object, ROWObject>(ROWObject.class) {
            @Override
            public boolean matchesSafely(ROWObject rowObject) {
                return itemTextMatcher.matches(rowObject.text);
            }
    
            @Override
            public void describeTo(Description description) {
                description.appendText("with rowObject: ");
                itemTextMatcher.describeTo(description);
            }
        };
    }
    

    顺便说一句,“GridView是一个ViewGroup,它在二维可滚动二维网格中显示项目。”

    10-07 12:49
    查看更多