简体   繁体   English

如何从 uiautomator 获取 android 设备的正确资源 ID?

[英]how to get the correct resource id for an android device from uiautomator?

i have question about resource ids in uiautomator:我对 uiautomator 中的资源 ID 有疑问:

btn="id:/image_button_cancel"

why sometimes we add ".*" what is the meaning of that?为什么有时我们会添加“.*”,这是什么意思?

btn="id:/image_button_cancel.*"

I did not get your question exactly.我没有完全明白你的问题。 Can you please elaborate more?你能详细说明一下吗?

. . * is used to match the resourceId by regex. * 用于通过正则表达式匹配resourceId。

So id:/image_button_cancel.所以id:/image_button_cancel。 * means it will match any resourceId which starts with id:/image_button_cancel * 表示它将匹配任何以id:/image_button_cancel 开头的 resourceId

For Ex,例如,

id:/image_button_cancel_1 id:/image_button_cancel_1

id:/image_button_cancelQuick id:/image_button_cancelQuick

Like this...像这样...

It is a regular expression.它是一个正则表达式。 The dot means any character and the asterisk means zero or more repetitions.点表示任何字符,星号表示零次或多次重复。

So using btn="id:/image_button_cancel.*" will match any resource id that starts with "id:/image_button_cancel".所以使用 btn="id:/image_button_cancel.*" 将匹配任何以 "id:/image_button_cancel" 开头的资源 id。

Example (matched ids):示例(匹配的 ID):

id:/image_button_cancel
id:/image_button_cancel_action

Example (not matched ids):示例(不匹配的 ID):

id:/cancel
id:/image_button

Search about regex to understand it better.搜索正则表达式以更好地理解它。

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

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