Zhongjie Fan
Zhongjie Fan

Reputation: 65

Scroll and click a textview by matching keyword using Appium

App is made by react native. None of view or control has content-desc or resource-id.

I use Java, Appium 1.8.1. I want to scroll view, search Brazil and click that text programmatically.

I tried below line. Scrolling worked, but cannot find item by keyword. Anyone can help?

((AndroidDriver<MobileElement>) driver).findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"
            + ".className(\"android.widget.ScrollView\")).scrollIntoView(new UiSelector().text(\"Brazil\"))").click();

Thank you. enter image description here

Upvotes: 2

Views: 797

Answers (1)

Zhongjie Fan
Zhongjie Fan

Reputation: 65

The line in the question can actually work. But just not efficient and failed frequently. Below line is better.

((AndroidDriver<MobileElement>) driver).findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"
            + ".className(\"android.widget.ScrollView\")).getChildByText(new UiSelector().className(\"android.widget.TextView\"), "+DESTINATION_ELEMENT_TEXT+")").click();

Upvotes: 1

Related Questions