Function

getFirstLinkBounds

Returns the bounds of the first link matching the predicate, or if that link spans multiple lines, returns the bounds of the first line of the link.

hoverFirstLinkInText

@Sampled
fun hoverFirstLinkInText() {
    // Example of hovering over the first link in test
    val firstLinkBounds =
        composeTestRule.onNodeWithText("YOUR_TEXT_WITH_LINK").getFirstLinkBounds {
            (it.item as? LinkAnnotation.Url)?.url == "YOUR_URL"
        }

    composeTestRule.onNodeWithText("YOUR_TEXT_WITH_LINK").performMouseInput {
        moveTo(firstLinkBounds!!.center)
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: