Android - Espresso - scrolling to a non-list View item

前端 未结 3 1110
Happy的楠姐
Happy的楠姐 2021-01-02 05:08

Is there a general approach for scrolling to non-list View items that are not yet visible on the screen?

Without any precautions, Espresso will indicate that \"No V

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 05:45

    According to the scrollTo JavaDoc, to use the code you specified ( onView( withId( R.id.button)).perform( scrollTo(), click()); ), the preconditions are: "must be a descendant of ScrollView" and "must have visibility set to View.VISIBLE". If that is the case, then that will work just fine.

    If it is in an AdapterView, then you should use onData instead. In some cases, you may have to implement the AdapterViewProtocol, if your AdapterView is not well behaved.

    If it is neither in an AdapterView nor a child of a ScrollView, then you would have to implement a custom ViewAction.

提交回复
热议问题