如何执行向上滚动操作,直到找出使用浓缩咖啡的元素



我是浓缩咖啡的新手,我想滚动到屏幕顶部,直到找不到元素。如何在浓缩咖啡中做到这一点?在这里需要一些帮助。

我想滚动到顶部以单击"发送"按钮。如何实现这一点?

没有必要滚动到顶部,你也可以使用scrollTo,这是ViewActionEspresso已经定义的方法。

public static ViewAction scrollTo() {
return actionWithAssertions(new ScrollToAction());
}

您还必须检查此设置以使其正常工作。

/**
* Returns an action that scrolls to the view.<br>
* <br>
* View preconditions:
*
* <ul>
*   <li>must be a descendant of ScrollView
*   <li>must have visibility set to View.VISIBLE
*       <ul>
*/

那么,你必须做什么?首先知道Button的id或任何View,为此,您可以简单地使用:

onView(withId(R.id.yourButtonId))

好的,那么你要做的就是执行一个scrollTo(),然后你这样做:

onView(withId(R.id.yourButtonId)).perform(ViewActions.scrollTo())

然后它应该转到执行滚动的元素。

最后,如果您想单击该View您可以在perform()方法上添加操作,如下所示:

/**
* Performs the given action(s) on the view selected by the current view matcher. If more than one
* action is provided, actions are executed in the order provided with precondition checks running
* prior to each action.
*
* @param viewActions one or more actions to execute.
* @return this interaction for further perform/verification calls.
*/

因此,单击就像编写click()一样简单,然后最终代码应该是

onView(withId(R.id.yourButtonId)).perform(ViewActions.scrollTo(), ViewActions.click())

最新更新