---
title: "SemanticsNodeInteractionCollection"
description: "Represents a collection of semantics nodes and the path to fetch them from the semantics tree.
One can interact with these nodes by performing assertions such as [assertCountEquals], or
navigate to other nodes such as [get].

An instance of [SemanticsNodeInteractionCollection] can be obtained from
[onAllNodes][SemanticsNodeInteractionsProvider.onAllNodes] and convenience methods that use a
specific filter, such as [onAllNodesWithText].

For example, here is how you verify that there are exactly two clickable items:"
type: "class"
---

<div class='type'>Class</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
class SemanticsNodeInteractionCollection
constructor(
    internal val testContext: TestContext,
    internal val useUnmergedTree: Boolean,
    internal val selector: SemanticsSelector,
)
```


Represents a collection of semantics nodes and the path to fetch them from the semantics tree.
One can interact with these nodes by performing assertions such as `assertCountEquals`, or
navigate to other nodes such as `get`.

An instance of `SemanticsNodeInteractionCollection` can be obtained from
`onAllNodes` and convenience methods that use a
specific filter, such as `onAllNodesWithText`.

For example, here is how you verify that there are exactly two clickable items:


## Secondary Constructors

```kotlin
constructor(
    testContext: TestContext,
    useUnmergedTree: Boolean,
    matcher: SemanticsMatcher,
) : this(testContext, useUnmergedTree, SemanticsSelector(matcher))
```

## Functions

```kotlin
fun fetchSemanticsNodes(
        atLeastOneRootRequired: Boolean = true,
        errorMessageOnFail: String? = null,
    ): List<SemanticsNode>
```


Returns the semantics nodes captured by this object.

Note: Accessing this object involves synchronization with your UI. If you are accessing this
multiple times in one atomic operation, it is better to cache the result instead of calling
this API multiple times.

#### Parameters

| | |
| --- | --- |
| atLeastOneRootRequired | Whether to throw an error in case there is no compose content in the current test app. |
| errorMessageOnFail | Custom error message to append when this fails to retrieve the nodes. |



```kotlin
operator fun get(index: Int): SemanticsNodeInteraction
```


Retrieve node at the given index of this collection.

Any subsequent operation on its result will expect exactly one element found (unless
`SemanticsNodeInteraction.assertDoesNotExist` is used) and will throw `AssertionError` if
none or more than one element is found.



## Code Examples

### verifyTwoClickableNodes
```kotlin
fun verifyTwoClickableNodes() {
    composeTestRule.onAllNodes(hasClickAction()).assertCountEquals(2)
}
```

