I am trying to automate clicking the item of the dynamic scrollable list item containing specific text. The text of list item is getting using api call, it may/will be changed based on api response.
For example suppose i have 3 list item say apple, mango and banana. If i want to click on item that contain the text banana, how can i do that?
My Appium Desktop inspector my xml file for the dynamic list looks like following
<android.view.ViewGroup content-desc="Dashboard_lv_Container"> <android.view.ViewGroup> <android.widget.ListView content-desc="Dashboard_lv"> <android.widget.LinearLayout> <android.view.ViewGroup> <android.widget.FrameLayout content-desc="item_1"> <android.view.ViewGroup> <android.view.ViewGroup> <android.widget.TextView> <android.view.ViewGroup> <android.widget.ImageView> <android.widget.LinearLayout> <android.view.ViewGroup> <android.widget.FrameLayout content-desc="item_2"> <android.view.ViewGroup> <android.view.ViewGroup> <android.widget.TextView> <android.view.ViewGroup> <android.widget.ImageView>
I want to select the item with certain text contain in android.widget.TextView. How can i do that?
I solve it using the UiSelector
try {
MobileElement element=driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().text(\"banana\")"));
element.click();
}catch (org.openqa.selenium.NoSuchElementException e){
System.out.println("Element not found");
}
For the scrollable list i did it using UiScrollable description
try {
MobileElement element=driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(\"new UiSelector().description(\"Dashboard_lv\")\").getChildByText(\"new UiSelector().text(\"banana\")\")"));
element.click();
}catch (org.openqa.selenium.NoSuchElementException e){
System.out.println("Element not found");
}