Appium中get_attribute函数的使用

本文详细介绍了Appium中get_attribute方法的可用参数,包括字符串类型如name、text、className等,布尔类型如enabled、checkable等,以及一些虽无法通过此方法获取但在uiautomatorviewer中可见的属性。重点对比了name与text参数的区别,强调了name参数的适用性和全面性。

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吧,哈哈哈,涨了小小的一个知识了 !

我调用执行这个方法,方法如下: def get_brightness(self): try: result = self.driver.execute_script( 'mobile: shell', { 'command': 'settings', 'args': ['get', 'system', 'screen_brightness'], 'includeStderr': True, 'timeout': 5000 } ) brightness_value = int(result['stdout'].strip()) print(f"当前设备亮度:{brightness_value}") return brightness_value except Exception as e: print(f"亮度获取失败:{e}") 报错信息如下:亮度获取失败:Message: An unknown server-side error occurred while processing the command. Original error: Potentially insecure feature 'adb_shell' has not been enabled. If you want to enable this feature and accept the security ramifications, please do so by following the documented instructions at https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/security.md Stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Potentially insecure feature 'adb_shell' has not been enabled. If you want to enable this feature and accept the security ramifications, please do so by following the documented instructions at https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/security.md at getResponseForW3CError (D:\auto_deploy_hytest\nodejs\node_global\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9) at asyncHandler (D:\auto_deploy_hytest\nodejs\node_global\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:380:37) None
最新发布
09-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值