---
title: "printToString"
description: "Prints all the semantics nodes information it holds into string.

By default this also prints all the sub-hierarchy. This can be changed by setting a custom max
depth in [maxDepth].

Note that this will fetch the latest snapshot of nodes it sees in the hierarchy for the IDs it
collected before. So the output can change over time if the tree changes."
type: "function"
---

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


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun SemanticsNodeInteraction.printToString(
    /*@IntRange(from = 0)*/
    maxDepth: Int = Int.MAX_VALUE
): String
```


Prints all the semantics nodes information it holds into string.

By default this also prints all the sub-hierarchy. This can be changed by setting a custom max
depth in `maxDepth`.

Note that this will fetch the latest snapshot of nodes it sees in the hierarchy for the IDs it
collected before. So the output can change over time if the tree changes.

#### Parameters

| | |
| --- | --- |
| maxDepth | Max depth of the nodes in hierarchy to print. Zero will print just this node. Must not be negative. |




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


```kotlin
fun SemanticsNodeInteractionCollection.printToString(
    /*@IntRange(from = 0)*/
    maxDepth: Int = 0
): String
```


Prints all the semantics nodes information it holds into string.

By default this does not print nodes sub-hierarchies. This can be changed by setting a custom max
depth in `maxDepth`.

Note that this will fetch the latest snapshot of nodes it sees in the hierarchy for the IDs it
collected before. So the output can change over time if the tree changes.

#### Parameters

| | |
| --- | --- |
| maxDepth | Max depth of the nodes in hierarchy to print. Zero will print nodes in this collection only. Must not be negative. |




