performFirstLinkClick

Function

Common
fun SemanticsNodeInteraction.performFirstLinkClick(
    predicate: (AnnotatedString.Range<LinkAnnotation>) -> Boolean = { true }
): SemanticsNodeInteraction

For a first link matching the predicate performs a click on it.

A link in a Text composable is defined by a LinkAnnotation of the AnnotatedString.

Code Examples

touchInputOnFirstSpecificLinkInText

fun touchInputOnFirstSpecificLinkInText() {
    // Example of clicking on a link in test
    composeTestRule.onNodeWithText("YOUR_TEXT_WITH_LINK").performFirstLinkClick {
        (it.item as? LinkAnnotation.Url)?.url == "YOUR_URL"
    }
}