# RecyclerViewActions

# RecyclerViewActions

Artifact:[androidx.test.espresso:espresso-contrib](https://developer.android.com/jetpack/androidx/releases/test-espresso)  
[View Source](https://cs.android.com/search?q=file:androidx/test/espresso/contrib/RecyclerViewActions.java+class:androidx.test.espresso.contrib.RecyclerViewActions)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/espresso/contrib/RecyclerViewActions "View this page in Java")

<br />

```
class RecyclerViewActions
```

<br />

*** ** * ** ***

[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)s to interact[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView). RecyclerView works differently than[AdapterView](https://developer.android.com/reference/android/widget/AdapterView.html). In fact, RecyclerView is not an AdapterView anymore, hence it can't be used in combination with[onData](https://developer.android.com/reference/kotlin/androidx/test/espresso/Espresso#onData(org.hamcrest.Matcher<? extends java.lang.Object>)).

To use[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)s in this class use[onView](https://developer.android.com/reference/kotlin/androidx/test/espresso/Espresso#onView(org.hamcrest.Matcher<android.view.View>))with a[`Matcher
`](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)that matches your[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView), then perform a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)from this class.

## Summary

|                                                                                                                                                                                                   ### Nested types                                                                                                                                                                                                   |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `interface `[RecyclerViewActions.PositionableRecyclerViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction)` : `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction) Most RecyclerViewActions are given a matcher to select a particular view / viewholder within the RecyclerView. |

|                                                                                          ### Public functions                                                                                           |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[RecyclerViewActions.PositionableRecyclerViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction)`!` | `<VH : `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`?> `[actionOnHolderItem](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions#actionOnHolderItem(org.hamcrest.Matcher<VH>,androidx.test.espresso.ViewAction))`(` ` viewHolderMatcher: `[Matcher](https://junit.org/junit4/javadoc/4.12/org/hamcrest/Matcher.html)`<VH!>!,` ` viewAction: `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)`!` `)` Performs a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)on a view matched by viewHolderMatcher.                                                                        |
| `java-static `[RecyclerViewActions.PositionableRecyclerViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction)`!` | `<VH : `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`?> `[actionOnItem](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions#actionOnItem(org.hamcrest.Matcher<android.view.View>,androidx.test.espresso.ViewAction))`(` ` itemViewMatcher: `[Matcher](https://junit.org/junit4/javadoc/4.12/org/hamcrest/Matcher.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`!>!,` ` viewAction: `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)`!` `)` Performs a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)on a view matched by viewHolderMatcher. |
| `java-static `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)`!`                                                                                         | `<VH : `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`?> `[actionOnItemAtPosition](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions#actionOnItemAtPosition(int,androidx.test.espresso.ViewAction))`(` ` position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` viewAction: `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)`!` `)` Performs a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)on a view at position.                                                                                                                    |
| `java-static `[RecyclerViewActions.PositionableRecyclerViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction)`!` | `<VH : `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`?> `[scrollTo](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions#scrollTo(org.hamcrest.Matcher<android.view.View>))`(itemViewMatcher: `[Matcher](https://junit.org/junit4/javadoc/4.12/org/hamcrest/Matcher.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`!>!)` Returns a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)which scrolls[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)to the view matched by itemViewMatcher.                                                |
| `java-static `[RecyclerViewActions.PositionableRecyclerViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions.PositionableRecyclerViewAction)`!` | `<VH : `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`?> `[scrollToHolder](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions#scrollToHolder(org.hamcrest.Matcher<VH>))`(` ` viewHolderMatcher: `[Matcher](https://junit.org/junit4/javadoc/4.12/org/hamcrest/Matcher.html)`<VH!>!` `)` Returns a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)which scrolls[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)to the view matched by viewHolderMatcher.                                                                                                              |
| `java-static `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)                                                                                            | `<VH : `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`?> `[scrollToLastPosition](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions#scrollToLastPosition())`()` Returns a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)which scrolls[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)to the last position.                                                                                                                                                                                                                                                          |
| `java-static `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)`!`                                                                                         | `<VH : `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`?> `[scrollToPosition](https://developer.android.com/reference/kotlin/androidx/test/espresso/contrib/RecyclerViewActions#scrollToPosition(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)which scrolls[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)to a position.                                                                                                                                                                               |

## Public functions

### actionOnHolderItem

```
java-static fun <VH : RecyclerView.ViewHolder?> actionOnHolderItem(
    viewHolderMatcher: Matcher<VH!>!,
    viewAction: ViewAction!
): RecyclerViewActions.PositionableRecyclerViewAction!
```

Performs a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)on a view matched by viewHolderMatcher.

1. Scroll Recycler View to the view matched by itemViewMatcher
2. Perform an action on the matched view

Note: actionOnItem method is not overloaded, method overloading with generic parameters is not possible.  

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `viewHolderMatcher: `[Matcher](https://junit.org/junit4/javadoc/4.12/org/hamcrest/Matcher.html)`<VH!>!`         | a[`Matcher `](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)that matches an item view holder in[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView) |
| `viewAction: `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)`!` | the action that is performed on the view matched by viewHolderMatcher                                                                                                                                                            |

|                                                              Throws                                                               |
|-----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| [androidx.test.espresso.PerformException](https://developer.android.com/reference/kotlin/androidx/test/espresso/PerformException) | if there are more than one items matching given viewHolderMatcher. |

### actionOnItem

```
java-static fun <VH : RecyclerView.ViewHolder?> actionOnItem(
    itemViewMatcher: Matcher<View!>!,
    viewAction: ViewAction!
): RecyclerViewActions.PositionableRecyclerViewAction!
```

Performs a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)on a view matched by viewHolderMatcher.

1. Scroll Recycler View to the view matched by itemViewMatcher
2. Perform an action on the matched view

|                                                                                 Parameters                                                                                  |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `itemViewMatcher: `[Matcher](https://junit.org/junit4/javadoc/4.12/org/hamcrest/Matcher.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`!>!` | a[`Matcher `](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)that matches an item view in[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView) |
| `viewAction: `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)`!`                                                             | the action that is performed on the view matched by itemViewMatcher                                                                                                                                                       |

|                                                              Throws                                                               |
|-----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| [androidx.test.espresso.PerformException](https://developer.android.com/reference/kotlin/androidx/test/espresso/PerformException) | if there are more than one items matching given viewHolderMatcher. |

### actionOnItemAtPosition

```
java-static fun <VH : RecyclerView.ViewHolder?> actionOnItemAtPosition(
    position: Int,
    viewAction: ViewAction!
): ViewAction!
```

Performs a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)on a view at position.

1. Scroll Recycler View to position
2. Perform an action on the view at position

|                                                   Parameters                                                    |
|-----------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                         | position of a view in[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView) |
| `viewAction: `[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)`!` | the action that is performed on the view matched by itemViewMatcher                                                           |

### scrollTo

```
java-static fun <VH : RecyclerView.ViewHolder?> scrollTo(itemViewMatcher: Matcher<View!>!): RecyclerViewActions.PositionableRecyclerViewAction!
```

Returns a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)which scrolls[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)to the view matched by itemViewMatcher.

This approach uses[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)s to find the target view. It will create one ViewHolder per item type and bind adapter data to the ViewHolder. If the itemViewMatcher matches a ViewHolder the current position of the View is used to perform a[scrollToPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#scrollToPosition(int)).  

|                                                                                 Parameters                                                                                  |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `itemViewMatcher: `[Matcher](https://junit.org/junit4/javadoc/4.12/org/hamcrest/Matcher.html)`<`[View](https://developer.android.com/reference/android/view/View.html)`!>!` | a[`Matcher `](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)that matches an item view in[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView) |

|                                                              Throws                                                               |
|-----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| [androidx.test.espresso.PerformException](https://developer.android.com/reference/kotlin/androidx/test/espresso/PerformException) | if there are more than one items matching given viewHolderMatcher. |

### scrollToHolder

```
java-static fun <VH : RecyclerView.ViewHolder?> scrollToHolder(
    viewHolderMatcher: Matcher<VH!>!
): RecyclerViewActions.PositionableRecyclerViewAction!
```

Returns a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)which scrolls[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)to the view matched by viewHolderMatcher.

This approach uses[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)s to find the target view. It will create one ViewHolder per item type and bind adapter data to the ViewHolder. If the itemViewMatcher matches a ViewHolder the current position of the View is used to perform a[scrollToPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#scrollToPosition(int)). Note: scrollTo method is not overloaded, method overloading with generic parameters is not possible.  

|                                               Parameters                                                |
|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `viewHolderMatcher: `[Matcher](https://junit.org/junit4/javadoc/4.12/org/hamcrest/Matcher.html)`<VH!>!` | a[`Matcher `](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)that matches an item view holder in[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView) |

|                                                              Throws                                                               |
|-----------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| [androidx.test.espresso.PerformException](https://developer.android.com/reference/kotlin/androidx/test/espresso/PerformException) | if there are more than one items matching given viewHolderMatcher. |

### scrollToLastPosition

```
java-static fun <VH : RecyclerView.ViewHolder?> scrollToLastPosition(): ViewAction
```

Returns a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)which scrolls[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)to the last position.  

### scrollToPosition

```
java-static fun <VH : RecyclerView.ViewHolder?> scrollToPosition(position: Int): ViewAction!
```

Returns a[ViewAction](https://developer.android.com/reference/kotlin/androidx/test/espresso/ViewAction)which scrolls[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)to a position.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|---------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | the position of the view to scroll to |