简体   繁体   中英

How to get all text having certain pattern in UIAutomator

I have a list of contacts which is scrollable. I want to get all contacts starting with +880 while scrolling. How can I use regex here? Here is my code

     ui_str = 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).getChildByText(new UiSelector().className("android.widget.TextView"), "+880")'
     current_group_members = admin_device.driver.find_elements_by_android_uiautomator(ui_str)

I've also resource id of each element com.test.communicator:id/phoneNumberTxt . Can I get all elements with this id? I've tried to use find_elements_by_id but It gets only visible items. I need all elements in the list.

You could search through the children by selecting those matching a text regex. See UiSelector.textMatches(...) for getting UiAutomator to use regex:

Per Javadoc:

Set the search criteria to match the visible text displayed in a layout element, using a regular expression. The text in the widget must match exactly with the string in your input argument. https://developer.android.com/reference/androidx/test/uiautomator/UiSelector#textmatches

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM