Appium+Python get_attribute函数使用

1、测试代码

import unittest
class testEx(unittest.TestCase):
"""docstring for testEx"""
def setUp(self):
     #自行补充desired_caps
    desired_caps=[]
    self.driver = webdriver.Remote('http://192.168.10.95:4723/wd/hub', desired_caps)
def test_AA(self):
      self.driver.find_elements_by_id('id').get_attribute('name')
def tearDown(self):
    pass
if __name__ == '__main__':
unittest.main()

2、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 来获取其中部分内容)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容