LexSav
LexSav

Reputation: 454

Find element by text inside another element using UISelector query

I have the following code snippet and the screenshot attached.

String query = "new UiScrollable(new UiSelector().className(\"androidx.recyclerview.widget.RecyclerView\"))" +
                ".scrollIntoView(new UiSelector().text(\"Test Group\"))";
driver.findElementByAndroidUIAutomator (query).click ();

What I want is to find an element with the text "Test Group" using UISelector, but inside the RecyclerView only (not searching the whole app source). What I get is the element inside search field instead (not in the RecyclerView).

Please advice. I know that I can get all searched elements using findElements(By.id("name")). But I want to use UI selector in this case.

enter image description here

Upvotes: 0

Views: 1809

Answers (1)

Yevhen Danchenko
Yevhen Danchenko

Reputation: 1099

With UiSelector you can use chaining:

String query = "new UiScrollable(resourseIdMatches(\".*recycler_view\")).scrollIntoView(resourseIdMatches(\".*recycler_view\")).childSelector(text(\"Text Group\")))";

In addition new UiSelector... part can be omitted. Appium does support this syntax.

Upvotes: 0

Related Questions