简体   繁体   English

如何在 UIAutomator 中获取具有特定模式的所有文本

[英]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.我想在滚动时获取所有以+880开头的联系人。 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 .我还有每个元素com.test.communicator:id/phoneNumberTxt的资源 ID。 Can I get all elements with this id?我可以获取具有此 ID 的所有元素吗? I've tried to use find_elements_by_id but It gets only visible items.我尝试使用find_elements_by_id但它只获取可见项目。 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:请参阅 UiSelector.textMatches(...) 以使 UiAutomator 使用正则表达式:

Per Javadoc:根据 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 https://developer.android.com/reference/androidx/test/uiautomator/UiSelector#textmatches

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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