Espresso click on specific words of text

Issue

In my espresso test I want to tap on a certain part of a text element with the idSwitchTextView . The full text reads ” Are you a member? Login with email” When you click on the login with email it switches the view of the page.

When I use onView(withId(R.id.switchTextView)).perform(click()); The test passes but because there is initial text before the text I want to be clicked on it doesnt change view. How can I pin point and only touch the “Login with email” text?

Solution

You can do like this

onView(withId(R.id.switchTextView(matches(withText(containsString("Login with email"))));

Answered By – ugurcmk

Leave a Comment