Python + appium使用get_attribute等方法获取uiautomatorviewer的所有参数
Song • 277 次浏览 • 0 个回复 • 2020年12月03日

python中使用appium的get_attribute 方法不是我们在uiautomatorviewer
看到的所有属性都能获取的(此处的名称均为使用 get_attribute 时使用的属性名称)
可获取的:
字符串类型:
- name(返回 content-desc 或 text): get_attribute("name")不能保证返回的一定是 content-desc (content-desc 为空时会返回 text 属性值)
- text(返回 text)
- className(返回 class,只有 API=>18 才能支持)
- resourceId(返回
resource-id
,只有 API=>18 才能支持)
布尔类型(如果无特殊说明, get_attribute 里面使用的属性名称和 uiautomatorviewer 里面的一致):
- enabled
- checkable
- checked
- clickable
- focusable
- focused
- longClickable(返回 long-clickable)
- scrollable
- selected
- displayed(此元素是否在当前界面存在。调用的是 UIObject 的 exists() 方法,详情请看http://developer.android.com/reference/android/support/test/uiautomator/UiObject.html#exists())
获取不到,但会显示在 uiautomatorviewer 中的属性:
- index
- package
- password
- bounds:可通过 position 来获取位置,参考下方获取方法
一、获取元素坐标的方法
size获取元素的宽、高
ele_size = driver.find_element_by_xx('xx').size
# 元素的宽
width = ele_size['width']
# 元素的高
height = ele_size['height']
location获取元素左上角坐标
ele_coordinate = driver.find_element_by_xx('xx').location
# 元素左上角横坐标
x = ele_coordinate['x']
# 元素左上角纵坐标
y = ele_coordinate['y']
由此可以计算出元素其他的坐标
(x+width, y) # 右上角坐标
(x+width, y+height) # 右下角坐标
(x, y+height) # 左下角坐标
(x+width/2, y+height/2) # 元素中心点坐标
具体参考Python+Appium自动化测试之location与size获取元素坐标
原创文章,转载请注明 :Python + appium使用get_attribute等方法获取uiautomatorviewer的所有参数 - pytorch中文网
原文出处: https://ptorch.com/news/259.html
问题交流群 :168117787
- 没有评论