【Python自动化测试】Appium get_attribute使用方法

  • 官方文档
  • 文档不详细,可以下载源代码(以安卓为例)
  • 用AndroidStudio打开,可以查看可以过去的所有属性值
    在这里插入图片描述
CHECKABLE(new String[]{"checkable"}),
CHECKED(new String[]{"checked"}),
CLASS(new String[]{"class", "className"}),
CLICKABLE(new String[]{"clickable"}),
CONTENT_DESC(new String[]{"content-desc", "contentDescription"}),
ENABLED(new String[]{"enabled"}),
FOCUSABLE(new String[]{"focusable"}),
FOCUSED(new String[]{"focused"}),
LONG_CLICKABLE(new String[]{"long-clickable", "longClickable"}),
PACKAGE(new String[]{"package"}),
PASSWORD(new String[]{"password"}),
RESOURCE_ID(new String[]{"resource-id", "resourceId"}),
SCROLLABLE(new String[]{"scrollable"}),
SELECTION_START(new String[]{"selection-start"}),
SELECTION_END(new String[]{"selection-end"}),
SELECTED(new String[]{"selected"}),
TEXT(new String[]{"text", "name"}),
// The main difference of this attribute from the preceding one is that
// it does not replace null values with empty strings
ORIGINAL_TEXT(new String[]{"original-text"}, false, false),
BOUNDS(new String[]{"bounds"}),
INDEX(new String[]{"index"}, false, true),
DISPLAYED(new String[]{"displayed"}),
CONTENT_SIZE(new String[]{"contentSize"}, true, false);
  • 与selenium的get_attributed的不同在于有大量的移动端的属性值

基本使用实例:

from appium import webdriver
class TestGetAttr:
    def setup(self):
        desire_cap = {
            "platformName": "Android",
            "deviceName": "mvq8aaw4ca5tcamn",
            "appActivity": ".view.WelcomeActivityAlias",
            "appPackage": "com.xueqiu.android",
            "noReset": True
        }
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desire_cap)
        self.driver.implicitly_wait(10)

    def teardown(self):
        pass
        
    def test_get_attr(self):
        search_ele = self.driver.find_element_by_id("com.xueqiu.android:id/home_search")
        print(search_ele.get_attribute("resource-id"))
        print(search_ele.get_attribute("content-desc"))
        print(search_ele.get_attribute("bounds"))
        print(search_ele.get_attribute("clickable"))
        assert 'search' in search_ele.get_attribute("resource-id")

注意,在使用get_attribute方法之前需要实例化一个元素对象!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值