Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso click on specific substring inside a Textview

I have a layout that contains a textview, shown below that will contain some auto generated links in a block of text. When the user clicks the links, a window with relevant information is opened up.

screenshot of app

However, I cannot figure out how to get Espresso to click on the links at all. Have tried many variations of something like

matches(withText(containsString("45")))

but this either just doesn't work or makes espresso just click on the textbox itself, which doesn't do anything.

Is there any way to do this? Is it even possible within the limitations of Espresso?

like image 316
user2782067 Avatar asked Jul 01 '26 03:07

user2782067


1 Answers

You can use openLinkWithText(String linkText)

Returns an action that opens a link matching the given link text and uri matchers. The action is performed by invoking the link's onClick method (as opposed to actually issuing a click on the screen).

Here's an example to how to use it :

Espresso.onView(ViewMatchers
.withId(R.id.your_text_view_id))
.perform(ViewActions.openLinkWithText("45")); 

References : espresso-recipes-for-android

like image 77
Skizo-ozᴉʞS Avatar answered Jul 05 '26 17:07

Skizo-ozᴉʞS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!