android - 如何执行向上滚动操作,直到找出需要使用 espresso 的元素
问题描述
我是浓缩咖啡的新手,我想滚动到屏幕顶部,直到找不到元素。如何在浓缩咖啡中做到这一点?在这里需要一些帮助。
解决方案
我想滚动到顶部以单击发送按钮。如何做到这一点?
不需要滚动到顶部,你也可以使用scrollTo
,这是ViewAction
类已经定义的方法Espresso
。
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>
*/
那么,你必须做什么?首先知道 idButton
或任何东西View
,你可以简单地使用:
onView(withId(R.id.yourButtonId))
好的,那么您要做的就是执行 a 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())
推荐阅读
- jquery - 使用 Jquery 通过切换按钮切换多个音频
- python - 熊猫:根据其他值更改数据框中的值
- excel - Excel(版本 1902)宏 - 用于从网站获取数据的查询表运行速度非常慢
- javascript - 如何将值转换为十六进制以在javascript中的数组中发送
- python-3.x - 有没有办法使用 python 使用 googleapiclient 创建带有 pubsub 通知的预定查询?
- c# - 根据某些条件生成url
- python-sphinx - 在没有自定义警告的情况下在 sphinx 中导出 html
- python - 如何获取和处理另一个类中的对象列表?
- javascript - 如何在 Bar-Highcharts 库中显示每个图表的 xAxis 类别?
- bootstrap-4 - 当引导程序 4 已在网站中使用时,ConverseJs 模式无法正确显示