Appium中get_attribute函数的使用

get_attribute可用参数

字符串类型:

ps:获取 content-desc 的方法为 get_attribute("name"),而且还不能保证返回的一定是 content-desc (content-desc 为空时会返回 text 属性值)

name(返回 content-desc 或 text)
text(返回 text)
className(返回 class,只有 API=>18 才能支持)
resourceId(返回 resource-id,只有 API=>18 才能支持)

布尔类型(如果无特殊说明, get_attribute 里面使用的属性名称和 uiautomatorviewer 里面的一致):

enabled
checkable
checked
clickable
focusable
focused
longClickable
scrollable
selected

获取不到,但会显示在 uiautomatorviewer 中的属性:

index
package
password
bounds(可通过 get_position 来获取其中部分内容)
特别注意一点:

get_attribute(name)方法,比get_attribute(text)方法,更全一点,所以,name(返回 content-desc 或 text)
如果使用text,text没有值得时候,就会报错的,所以还是用name吧,哈哈哈,涨了小小的一个知识了 !

Appium中get_attribute函数的使用