转http://blog.csdn.net/bear_w/article/details/50330753

问题描述

当使用类似下面的代码获取元素的 content-desc 属性时,会报 NoSuchElement 错误:

# python
self.driver.find_element_by_id("id").get_attribute("content-desc")

但使用如下代码却能正常执行:

# python
self.driver.find_element_by_id("id").click()

很明显,这个错误原因不是找不到元素,而是 get_attribute 出问题。

总结

1、获取 content-desc 的方法为 get_attribute("name") ,而且还不能保证返回的一定是 content-desc (content-desc 为空时会返回 text 属性值)
2、get_attribute 方法不是我们在 uiautomatorviewer 看到的所有属性都能获取的(此处的名称均为使用 get_attribute 时使用的属性名称):

可获取的:

字符串类型:

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

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

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

  • index
  • package
  • password
  • bounds(可通过 get_position 来获取其中部分内容)

appium的get_attribute方法的更多相关文章

  1. 关于 appium get_attribute 方法的坑

    (得要学着看源码) 问题: self.driver.find_element_by_id("id").get_attribute("content-desc") ...

  2. Python Appium 元素定位方法简单介绍

    Python  Appium  元素定位 常用的八种定位方法(与selenium通用) # id定位 driver.find_element_by_id() # name定位 driver.find_ ...

  3. appium 元素定位方法汇总

    以上图为例,要定位到右下角的 我的 ,并点击 # appium的webdriver提供了11种元素定位方法,在selenium的基础上扩展了三个,可以在pycharm里面输入driver.find_e ...

  4. Appium + python - get_attribute获取value操作

    from appium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.w ...

  5. Python+Appium 查找 toast 方法的封装

    使用场景:在操作应用时常见toast弹框,通过toast弹框信息的获取判断当前的某个操作是否成功 引用的包:from selenium.webdriver.support import expecte ...

  6. appium获取toast方法

    配置toast请注意: 1.指定desired_caps["automationName"] = "UiAutomator2" 2.要求安装jdk1.8 64位 ...

  7. Appium + java截图方法

    public static void takeScreenShot(AndroidDriver<WebElement> driver) { File screenShotFile = dr ...

  8. Appium处理滑动方法是swipe

    滑动API:Swipe(int start x,int start y,int end x,int y,duration) 解释: int start x-开始滑动的x坐标:int start y - ...

  9. appium 使用send_keys方法时报错: driver.find_element_by_id("com.hmkx.zgjkj:id/layout_search_bar_input").send_keys("123")

    新手 使用send_keys方法时一直报错,上网查这个方法的用法,看着大家都是这么写的啊,后来直接搜索 报错信息,搜索结果的针对性就清楚多了. 原来是seleium版本太高导致的问题. 可以先在cmd ...

随机推荐

  1. c++之析构函数

    #include<iostream>using namespace std;class A{   public:    A(){cout<<"A constructi ...

  2. django学习之- session

    session和cookie关系:session依赖于cookie基于cookie做用户验证时,敏感信息不适合放在cookie中原理:cookie定义:保存在用户游览器端的键值对session定义:保 ...

  3. Python高级进阶(一)Python框架之Django入门

    传说中的Django Django由来 Django是一个开放源代码的Web应用框架,由Python写成.采用了MVC的框架模式,即模型M,视图V和控制器C.它最初是被开发来用于管理劳伦斯出版集团旗下 ...

  4. 纯Java Web项目下的Session共享方案收集(待实践)

    1.使用filter方法存储 这种方法比较推荐,因为它的服务器使用范围比较多,不仅限于tomcat ,而且实现的原理比较简单容易控制. 可以使用memcached-session-filter 官方网 ...

  5. c++之函数对象、bind函数

    函数对象实质上是一个实现了operator()--括号操作符--的类. class Add { public: int operator()(int a, int b) { return a + b; ...

  6. [RxJS] Implement RxJS `switchMap` by Canceling Inner Subscriptions as Values are Passed Through

    switchMap is mergeMap that checks for an "inner" subscription. If the "inner" su ...

  7. 什么是WPF? 秒懂 !

    一開始听到WPF.认为非常陌生.在百度百科等地方看完简单介绍之后.感觉更深奥.各种不懂啊! 在简单做了几个页面之后,发现.原来如此! So Easy 但又So Magic. 为什么说它简单?由于它简直 ...

  8. MySQL Study之--Percona Server版本号

    MySQL Study之--Percona Server版本号 1.简单介绍      Percona 为 MySQL 数据库server进行了改进.在功能和性能上较 MySQL 有着非常显著的提升. ...

  9. SQL 连接(JOIN)

    SQL 连接(JOIN) SQL join 用于把来自两个或多个表的行结合起来. SQL JOIN SQL JOIN 子句用于把来自两个或多个表的行结合起来,基于这些表之间的共同字段. 最常见的 JO ...

  10. linux系列之-—01 shell编程笔记

    一.特殊变量($0.$1.$2. $?. $# .$@. $*) shell编程中有一些特殊的变量可以使用.这些变量在脚本中可以作为全局变量来使用. 名称 说明 $0 脚本名称 $1-9 脚本执行时的 ...