![](/img/trans.png)
[英]how to get the correct resource id for an android device from uiautomator?
[英]How to get all text having certain pattern in UIAutomator
我有一個可滾動的聯系人列表。 我想在滾動時獲取所有以+880開頭的聯系人。 我如何在這里使用正則表達式? 這是我的代碼
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)
我還有每個元素com.test.communicator:id/phoneNumberTxt的資源 ID。 我可以獲取具有此 ID 的所有元素嗎? 我嘗試使用find_elements_by_id但它只獲取可見項目。 我需要列表中的所有元素。
您可以通過選擇與文本正則表達式匹配的子項來搜索子項。 請參閱 UiSelector.textMatches(...) 以使 UiAutomator 使用正則表達式:
根據 Javadoc:
使用正則表達式設置搜索條件以匹配布局元素中顯示的可見文本。 小部件中的文本必須與輸入參數中的字符串完全匹配。 https://developer.android.com/reference/androidx/test/uiautomator/UiSelector#textmatches
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.